fix(shell): paste through terminal.paste() and stop swallowing native paste - #1007
Open
mayankdebnath wants to merge 1 commit into
Open
fix(shell): paste through terminal.paste() and stop swallowing native paste#1007mayankdebnath wants to merge 1 commit into
mayankdebnath wants to merge 1 commit into
Conversation
… paste Both shell paste paths (the Ctrl/Cmd+V handler and the mobile shortcuts-panel Paste button) sent raw clipboard text as a socket input message, bypassing xterm's bracketed-paste wrapping (DECSET 2004) and newline normalization — multi-line pastes submitted or executed line-by-line in Claude Code's CLI, shells, and vim. Route both through terminal.paste(), whose onData output flows to the pty via the existing socket input subscription. The key handler also unconditionally cancelled the paste chord even when navigator.clipboard.readText was unavailable (plain-HTTP deployments have no navigator.clipboard), pasting nothing while suppressing the browser's native paste event that would have reached xterm's hidden textarea. Only intercept the chord when the async clipboard API is actually usable; otherwise let the native path handle it. Fixes siteboon#1006
Contributor
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughChangesTerminal paste handling
Sequence Diagram(s)sequenceDiagram
participant User
participant PasteHandler
participant ClipboardAPI
participant Xterm
participant PTY
User->>PasteHandler: Paste shortcut or mobile paste
PasteHandler->>ClipboardAPI: readText()
ClipboardAPI-->>PasteHandler: clipboard text
PasteHandler->>Xterm: paste(text)
Xterm->>PTY: normalized bracketed input
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1006 — two independent paste bugs in the Shell terminal:
handler and the mobile shortcuts-panel Paste button) sent raw clipboard text
as a socket
inputmessage, bypassing xterm's bracketed-paste wrapping(DECSET 2004) and
\n→\rnormalization. Apps that enable bracketed paste— Claude Code's CLI, modern shells, vim — treated every newline as Enter:
pasting a 5-line prompt into
claudesubmitted it 5 times.handler unconditionally cancelled the chord but only injected text when
navigator.clipboard.readTextexists — which it doesn't outside securecontexts, i.e. on the common self-hosted
http://<lan-ip>:3001setup. Thecancelled keydown also suppressed the browser's native paste event that
would have reached xterm's hidden textarea and pasted fine. (Right-click →
Paste always worked, because only the keydown was intercepted.)
The fix
terminal.paste(text). xterm applies bracketed-paste wrapping and newline normalization, then emits
onData, which alreadyflows to the pty through the existing socket input subscription — so the wire
protocol is unchanged.
API is actually usable; otherwise return
trueso the native paste eventreaches xterm's textarea (xterm handles bracketed paste for that path
itself). Plain Ctrl+V (no Shift) intentionally remains xterm's literal
^V,matching normal terminal semantics.
Two files, no dependency or protocol changes.
Verification
npm run lint(0 errors),npm run typecheck,npm run build, fullnode:testsuite — all pass.terminal.paste()confirmed against the bundled xterm 5.5.0source:
replace(/\r?\n/g, "\r")plus\x1b[200~…\x1b[201~wrapping whenDECSET 2004 is active, emitted via the normal data event.
Related history: #767 (macOS Cmd+V paste failing in the terminal).
Summary by CodeRabbit