fix(cli,tui): recall real paste content on up-arrow

Large pastes collapse to a placeholder in the composer, but input history
stored the placeholder — so up-arrow recall showed a truncated reference
(CLI) or lost the content entirely (TUI, where the `[[…]]` label has no
backing snip after submit).

Store the expanded content in history instead:
- CLI: `_inline_pastes()` expands `[Pasted text #N -> file]` into the buffer
  before `reset(append_to_history=True)`; also reused by the external editor
  (dedup). History nav suppresses re-collapse of recalled content.
- TUI: `dispatchSubmission` pushes `expandSnips(pasteSnips)(full)`; idempotent
  on label-free text so re-submitting a recalled entry stays stable.
This commit is contained in:
Brooklyn Nicholson 2026-07-20 23:23:40 -05:00
parent a41d280f95
commit 79af472582
4 changed files with 141 additions and 16 deletions

View file

@ -103,3 +103,41 @@ def test_open_external_editor_sets_skip_collapse_flag_during_expansion(tmp_path)
# Flag is consumed by _on_text_changed, but since no handler is attached
# in tests it stays True until the handler resets it.
assert cli_obj._skip_paste_collapse is True
def test_inline_pastes_stores_full_content(tmp_path):
"""History should recall the actual pasted text, not the placeholder."""
cli_obj = _make_cli()
paste_file = tmp_path / "paste.txt"
paste_file.write_text("line one\nline two", encoding="utf-8")
buffer = _FakeBuffer(text=f"[Pasted text #1: 2 lines \u2192 {paste_file}]")
cli_obj._inline_pastes(buffer)
assert buffer.text == "line one\nline two"
assert buffer.cursor_position == len("line one\nline two")
# Skip flag set so the resulting text-change doesn't re-collapse.
assert cli_obj._skip_paste_collapse is True
def test_inline_pastes_leaves_plain_text_untouched():
"""No placeholder → buffer text and collapse flag are unchanged."""
cli_obj = _make_cli()
buffer = _FakeBuffer(text="just a normal message")
cli_obj._inline_pastes(buffer)
assert buffer.text == "just a normal message"
assert cli_obj._skip_paste_collapse is False
def test_inline_pastes_missing_file_keeps_placeholder(tmp_path):
"""A recalled reference whose file is gone stays as the placeholder."""
cli_obj = _make_cli()
placeholder = f"[Pasted text #1: 2 lines \u2192 {tmp_path / 'gone.txt'}]"
buffer = _FakeBuffer(text=placeholder)
cli_obj._inline_pastes(buffer)
assert buffer.text == placeholder
assert cli_obj._skip_paste_collapse is False