From c21b071e770265f62cedfa994d251bdc4108c9ea Mon Sep 17 00:00:00 2001 From: 0xbyt4 <35742124+0xbyt4@users.noreply.github.com> Date: Thu, 26 Feb 2026 23:40:38 +0300 Subject: [PATCH] fix(cli): prevent paste detection from destroying multi-line input The _on_text_changed handler collapsed buffer contents into a file reference whenever the buffer had 5+ newlines, regardless of how those lines were entered. This meant manually typing with Alt+Enter would trigger the paste heuristic and silently replace the user's carefully typed input. Track the previous buffer length and only treat a change as a paste when more than one character is added at once (real pastes insert many characters in a single event, while typing adds one at a time). --- cli.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cli.py b/cli.py index 10d43ea7c..234428b83 100755 --- a/cli.py +++ b/cli.py @@ -2225,13 +2225,17 @@ class HermesCLI: # Paste collapsing: detect large pastes and save to temp file _paste_counter = [0] + _prev_text_len = [0] def _on_text_changed(buf): """Detect large pastes and collapse them to a file reference.""" text = buf.text line_count = text.count('\n') - # Heuristic: if text jumps to 5+ lines in one change, it's a paste - if line_count >= 5 and not text.startswith('/'): + chars_added = len(text) - _prev_text_len[0] + _prev_text_len[0] = len(text) + # Heuristic: a real paste adds many characters at once (not just a + # single newline from Alt+Enter) AND the result has 5+ lines. + if line_count >= 5 and chars_added > 1 and not text.startswith('/'): _paste_counter[0] += 1 # Save to temp file paste_dir = Path(os.path.expanduser("~/.hermes/pastes"))