Merge pull request #84 from 0xbyt4/fix/cli-paste-detection-false-positive
fix(cli): prevent paste detection from destroying multi-line input
This commit is contained in:
commit
9061c03b6d
1 changed files with 6 additions and 2 deletions
8
cli.py
8
cli.py
|
|
@ -2248,13 +2248,17 @@ class HermesCLI:
|
||||||
|
|
||||||
# Paste collapsing: detect large pastes and save to temp file
|
# Paste collapsing: detect large pastes and save to temp file
|
||||||
_paste_counter = [0]
|
_paste_counter = [0]
|
||||||
|
_prev_text_len = [0]
|
||||||
|
|
||||||
def _on_text_changed(buf):
|
def _on_text_changed(buf):
|
||||||
"""Detect large pastes and collapse them to a file reference."""
|
"""Detect large pastes and collapse them to a file reference."""
|
||||||
text = buf.text
|
text = buf.text
|
||||||
line_count = text.count('\n')
|
line_count = text.count('\n')
|
||||||
# Heuristic: if text jumps to 5+ lines in one change, it's a paste
|
chars_added = len(text) - _prev_text_len[0]
|
||||||
if line_count >= 5 and not text.startswith('/'):
|
_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
|
_paste_counter[0] += 1
|
||||||
# Save to temp file
|
# Save to temp file
|
||||||
paste_dir = Path(os.path.expanduser("~/.hermes/pastes"))
|
paste_dir = Path(os.path.expanduser("~/.hermes/pastes"))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue