Skip to content

feat(tui): expand paste markers on second paste#116

Merged
liruifengv merged 6 commits into
mainfrom
expland-clipbaord
May 27, 2026
Merged

feat(tui): expand paste markers on second paste#116
liruifengv merged 6 commits into
mainfrom
expland-clipbaord

Conversation

@liruifengv

Copy link
Copy Markdown
Collaborator

Related Issue

Problem

When pi-tui folds a large paste into a marker like [paste #1 +15 lines], there is no way to expand it back in the editor. Users who want to review or edit the pasted content have to delete the marker and paste again.

What changed

Added "second paste to expand" behavior to CustomEditor: when the cursor sits on a folded paste marker and the user pastes again (via Ctrl-V or terminal bracketed paste), the marker is replaced with the original pasted content instead of inserting new clipboard data.

Implementation details:

  • expandPasteMarkerAtCursor() — detects if the cursor is on a paste marker, retrieves the stored content from pi-tui's internal pastes Map, and replaces the marker via setText() (which supports undo via Ctrl-Z).
  • Two interception points in handleInput(): one for bracketed paste sequences (ESC[200~), one for the Ctrl-V keystroke (\x16). Both check for a marker at cursor before falling through to the normal paste flow.
  • A consumingPaste flag handles multi-chunk bracketed paste data — after expanding a marker, any remaining paste chunks from the terminal are discarded.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

When the cursor sits on a folded paste marker (e.g. `[paste #1 +15 lines]`)
and the user pastes again (Ctrl-V or bracketed paste), the marker is expanded
back to its original content instead of inserting new clipboard data.
@changeset-bot

changeset-bot Bot commented May 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0fbbd32

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fbb734da17

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread apps/kimi-code/src/tui/components/editor/custom-editor.ts Outdated
Comment thread apps/kimi-code/src/tui/components/editor/custom-editor.ts Outdated
Stop deleting the paste entry from the Map after expansion so that
undo → re-expand still works.
@pkg-pr-new

pkg-pr-new Bot commented May 27, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@0fbbd32
npx https://pkg.pr.new/@moonshot-ai/kimi-code@0fbbd32

commit: 0fbbd32

Accumulate chunks while consuming discarded paste data so a
split ESC[201~ across chunks still resets consumingPaste.
@liruifengv liruifengv merged commit 2c7a8cc into main May 27, 2026
6 checks passed
@liruifengv liruifengv deleted the expland-clipbaord branch May 27, 2026 12:19
@github-actions github-actions Bot mentioned this pull request May 27, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0fbbd327a4

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +229 to +233
if (this.consumeBuffer.includes(BRACKET_PASTE_END)) {
this.consumingPaste = false;
this.consumeBuffer = '';
}
return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve input after the bracketed paste terminator

When consumingPaste is true and the terminal coalesces the bracketed-paste terminator with following input in the same data event, e.g. chunk\x1b[201~x after a marker expansion, this branch clears the consume state but still returns without replaying the bytes after \x1b[201~. That drops the user's first keystroke or escape sequence after the paste instead of handling it normally.

Useful? React with 👍 / 👎.

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.

1 participant