Skip to content

feat(cli): preserve user input on multiline paste, treat paste blocks as solid objects#2607

Closed
crazywriter1 wants to merge 1 commit into
NousResearch:mainfrom
crazywriter1:fix/2404-multiline-paste-preserve-input
Closed

feat(cli): preserve user input on multiline paste, treat paste blocks as solid objects#2607
crazywriter1 wants to merge 1 commit into
NousResearch:mainfrom
crazywriter1:fix/2404-multiline-paste-preserve-input

Conversation

@crazywriter1

Copy link
Copy Markdown
Contributor

Summary

Fixes #2404

  • Preserve existing input: Move paste collapsing into handle_paste (BracketedPaste handler) so only the pasted content is saved to file. Existing buffer text stays intact — the placeholder is inserted at the cursor position with a newline separator instead of replacing the entire buffer.
  • Solid object navigation: Left/Right arrow keys jump over [Pasted text ...] reference blocks as solid objects. If the cursor somehow lands inside a block (e.g. via Home key), it escapes on the next arrow press.
  • Solid object deletion: Backspace/Delete remove the entire paste reference block at once, including the preceding/following newline separator.
  • Multiple paste blocks: Each paste gets its own counter and temp file. Users can paste multiple blocks, add text above/below/between them.
  • Submit expansion: Changed from re.match (single ref at buffer start) to re.sub (all refs expanded inline), preserving surrounding user text. Display shows user text + paste block count.
  • Fallback guard: Added _paste_just_collapsed flag so the _on_text_changed heuristic (fallback for terminals without bracketed paste) doesn't double-collapse when handle_paste already handled it.

Test plan

  • 22 new unit tests in tests/test_cli_paste_collapse.py — all passing
    • Paste collapse preserves user text (3 tests)
    • Paste ref expansion on submit: single, multiple, mixed with user text, missing file (5 tests)
    • Cursor navigation: left/right jump, middle escape, end boundary, normal movement (6 tests)
    • Backspace/Delete: whole block removal, normal text unaffected, correct ref targeting (6 tests)
    • _on_text_changed fallback: flag skip + fallback still works (2 tests)
  • Manual test: type text, paste 5+ line block, verify text preserved and placeholder inserted below
  • Manual test: arrow keys skip over paste block, backspace/delete remove entire block
  • Manual test: paste multiple blocks, submit, verify all expanded correctly

… as solid objects

- Move paste collapsing into handle_paste (BracketedPaste handler) so
  only the pasted content is saved to file; existing buffer text is kept
- Insert paste placeholder at cursor position with newline separator
  instead of replacing the entire buffer
- Add _paste_just_collapsed flag to prevent _on_text_changed fallback
  from double-collapsing when bracketed paste already handled it
- Left/Right arrow keys jump over paste reference blocks as solid objects
- Backspace/Delete remove entire paste reference block at once
- Support multiple paste blocks in a single input buffer
- Expand all paste references inline on submit (re.sub instead of
  re.match), preserving surrounding user text
- Add 22 unit tests covering paste collapse, expansion, cursor
  navigation, and deletion behavior

Closes NousResearch#2404

Made-with: Cursor
teknium1 added a commit that referenced this pull request Mar 25, 2026
When pasting 5+ lines, the CLI previously replaced the entire input
buffer with a file reference placeholder. If the user had already typed
a question, it was lost.

Fix: move paste collapsing into handle_paste (BracketedPaste handler)
so only the pasted content is saved to file. The placeholder is inserted
at the cursor position, preserving existing buffer text.

Also fixes:
- Multi-ref expansion on submit (re.sub instead of re.match) so
  multiple paste blocks and surrounding text are all preserved
- Double-collapse prevention via _paste_just_collapsed flag
- Consistent Unicode arrow character across all paste paths

Salvaged from PR #2607 by crazywriter1 (option B: core fix only,
without keybinding overrides for solid-object navigation/deletion).
@teknium1

Copy link
Copy Markdown
Contributor

The core fix (preserve text on paste + multi-ref expansion + double-collapse prevention) was merged via salvage PR. The keybinding overrides for solid-object navigation/deletion were omitted to keep complexity down. Thanks @crazywriter1!

teknium1 added a commit that referenced this pull request Mar 25, 2026
When pasting 5+ lines, the CLI previously replaced the entire input
buffer with a file reference placeholder. If the user had already typed
a question, it was lost.

Fix: move paste collapsing into handle_paste (BracketedPaste handler)
so only the pasted content is saved to file. The placeholder is inserted
at the cursor position, preserving existing buffer text.

Also fixes:
- Multi-ref expansion on submit (re.sub instead of re.match) so
  multiple paste blocks and surrounding text are all preserved
- Double-collapse prevention via _paste_just_collapsed flag
- Consistent Unicode arrow character across all paste paths

Salvaged from PR #2607 by crazywriter1 (option B: core fix only,
without keybinding overrides for solid-object navigation/deletion).
@teknium1 teknium1 closed this Mar 25, 2026
outsourc-e pushed a commit to outsourc-e/hermes-agent that referenced this pull request Mar 26, 2026
When pasting 5+ lines, the CLI previously replaced the entire input
buffer with a file reference placeholder. If the user had already typed
a question, it was lost.

Fix: move paste collapsing into handle_paste (BracketedPaste handler)
so only the pasted content is saved to file. The placeholder is inserted
at the cursor position, preserving existing buffer text.

Also fixes:
- Multi-ref expansion on submit (re.sub instead of re.match) so
  multiple paste blocks and surrounding text are all preserved
- Double-collapse prevention via _paste_just_collapsed flag
- Consistent Unicode arrow character across all paste paths

Salvaged from PR NousResearch#2607 by crazywriter1 (option B: core fix only,
without keybinding overrides for solid-object navigation/deletion).
angelburgosrosado pushed a commit to angelburgosrosado/hermes-agent that referenced this pull request Apr 27, 2026
When pasting 5+ lines, the CLI previously replaced the entire input
buffer with a file reference placeholder. If the user had already typed
a question, it was lost.

Fix: move paste collapsing into handle_paste (BracketedPaste handler)
so only the pasted content is saved to file. The placeholder is inserted
at the cursor position, preserving existing buffer text.

Also fixes:
- Multi-ref expansion on submit (re.sub instead of re.match) so
  multiple paste blocks and surrounding text are all preserved
- Double-collapse prevention via _paste_just_collapsed flag
- Consistent Unicode arrow character across all paste paths

Salvaged from PR NousResearch#2607 by crazywriter1 (option B: core fix only,
without keybinding overrides for solid-object navigation/deletion).
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 2026
When pasting 5+ lines, the CLI previously replaced the entire input
buffer with a file reference placeholder. If the user had already typed
a question, it was lost.

Fix: move paste collapsing into handle_paste (BracketedPaste handler)
so only the pasted content is saved to file. The placeholder is inserted
at the cursor position, preserving existing buffer text.

Also fixes:
- Multi-ref expansion on submit (re.sub instead of re.match) so
  multiple paste blocks and surrounding text are all preserved
- Double-collapse prevention via _paste_just_collapsed flag
- Consistent Unicode arrow character across all paste paths

Salvaged from PR NousResearch#2607 by crazywriter1 (option B: core fix only,
without keybinding overrides for solid-object navigation/deletion).
olympus-terminal pushed a commit to olympus-terminal/hermes-agent that referenced this pull request May 16, 2026
When pasting 5+ lines, the CLI previously replaced the entire input
buffer with a file reference placeholder. If the user had already typed
a question, it was lost.

Fix: move paste collapsing into handle_paste (BracketedPaste handler)
so only the pasted content is saved to file. The placeholder is inserted
at the cursor position, preserving existing buffer text.

Also fixes:
- Multi-ref expansion on submit (re.sub instead of re.match) so
  multiple paste blocks and surrounding text are all preserved
- Double-collapse prevention via _paste_just_collapsed flag
- Consistent Unicode arrow character across all paste paths

Salvaged from PR NousResearch#2607 by crazywriter1 (option B: core fix only,
without keybinding overrides for solid-object navigation/deletion).
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
When pasting 5+ lines, the CLI previously replaced the entire input
buffer with a file reference placeholder. If the user had already typed
a question, it was lost.

Fix: move paste collapsing into handle_paste (BracketedPaste handler)
so only the pasted content is saved to file. The placeholder is inserted
at the cursor position, preserving existing buffer text.

Also fixes:
- Multi-ref expansion on submit (re.sub instead of re.match) so
  multiple paste blocks and surrounding text are all preserved
- Double-collapse prevention via _paste_just_collapsed flag
- Consistent Unicode arrow character across all paste paths

Salvaged from PR NousResearch#2607 by crazywriter1 (option B: core fix only,
without keybinding overrides for solid-object navigation/deletion).
Egavasyug pushed a commit to Egavasyug/hermes-agent that referenced this pull request Jun 10, 2026
When pasting 5+ lines, the CLI previously replaced the entire input
buffer with a file reference placeholder. If the user had already typed
a question, it was lost.

Fix: move paste collapsing into handle_paste (BracketedPaste handler)
so only the pasted content is saved to file. The placeholder is inserted
at the cursor position, preserving existing buffer text.

Also fixes:
- Multi-ref expansion on submit (re.sub instead of re.match) so
  multiple paste blocks and surrounding text are all preserved
- Double-collapse prevention via _paste_just_collapsed flag
- Consistent Unicode arrow character across all paste paths

Salvaged from PR NousResearch#2607 by crazywriter1 (option B: core fix only,
without keybinding overrides for solid-object navigation/deletion).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: CLI: Don't let multiline pastes remove user input, treat multiline pastes as an 'object' you can cursor around better

2 participants