Skip to content

feat(tui): expand collapsed paste placeholder when pasting again - #51766

Closed
yulong-ge wants to merge 1 commit into
anomalyco:devfrom
yulong-ge:paste-expand
Closed

yulong-ge wants to merge 1 commit into
anomalyco:devfrom
yulong-ge:paste-expand

Conversation

@yulong-ge

Copy link
Copy Markdown

What does this PR do?

Closes #8501.

Pasting again while the cursor sits on a collapsed paste placeholder ([Pasted ~N lines]) expands it back into the original text instead of inserting new clipboard content. This mirrors the behavior users know from other CLI agents: paste collapses, pressing paste again expands.

Demo

Buffer: check [Pasted ~3 lines] (cursor right after the placeholder) -> Cmd+V -> check alpha\nbeta\ngamma

Why this design

  • No new keybind: reuses the existing prompt.paste command and the bracketed-paste path, so the same shortcut that created the placeholder toggles it back. This keeps keybinds clean (a concern raised on feat(tui): Allow to expand pasted text (AKA "pasted summary") #8496) and gives the interaction for free on both paths.
  • Works for both entry points: explicit prompt.paste dispatch (clipboard read) and terminal bracketed paste (onPaste), which is what Cmd+V produces in iTerm/Terminal.
  • Cursor-adjacent detection: expansion triggers when the cursor is on the placeholder range or right after it (the trailing space pasteText inserts). Moving the cursor elsewhere and pasting inserts clipboard content as before.
  • Text parts only: file/image/agent extmarks sharing the same prompt-part typeId are ignored, so pasting over an [Image 1] badge still pastes.

Implementation

  • packages/tui/src/prompt/part.ts: adds pastedTextExtmarkAtOffset (cursor-on-placeholder check incl. the trailing space) and expandPastedTextPlaceholder (finds the text-part extmark at the cursor, deletes the placeholder range, re-inserts the stored text in place, keeps remaining extmarks adjusted by the buffer's own hooks).
  • packages/tui/src/component/prompt/index.tsx: calls it at the top of the prompt.paste command and the onPaste handler; on expansion it re-syncs prompt parts so the removed text part is dropped and other parts keep their ranges.

How did you verify your code works?

  • New unit tests in packages/tui/test/prompt/paste-expand.test.tsx: offset matching, single expansion with cursor position check, no-op second paste, expanding only the placeholder under the cursor when several exist, and ignoring non-text extmarks (e.g. file badges).
  • bun test in packages/tui: 199 tests pass, bun typecheck clean.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Sep 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@yulong-ge

Copy link
Copy Markdown
Author

Closing: author decided not to pursue upstream submission.

@yulong-ge yulong-ge closed this Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs:compliance This means the issue will auto-close after 2 hours.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Allow to expand the pasted text (e.g. [Pasted ~1 lines])

1 participant