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).
This commit is contained in:
8
cli.py
8
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"))
|
||||
|
||||
Reference in New Issue
Block a user