fix(shell): paste through terminal.paste() and stop swallowing native paste - #1007
fix(shell): paste through terminal.paste() and stop swallowing native paste#1007mayankdebnath wants to merge 3 commits 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
|
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 |
There was a problem hiding this comment.
Pull request overview
This PR fixes terminal paste behavior in the Shell by ensuring pasted text flows through xterm’s terminal.paste() path (to get bracketed-paste wrapping and newline normalization) and by avoiding swallowing paste key chords when the async Clipboard API isn’t available (notably on plain-HTTP deployments).
Changes:
- Mobile shortcuts “Paste” button now uses
terminal.paste(text)instead of sending raw input over the socket. - Desktop paste key handler now allows native paste to proceed when
navigator.clipboard.readTextis unavailable, and otherwise usesterminal.paste(text)to preserve bracketed paste semantics.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/components/shell/view/subcomponents/TerminalShortcutsPanel.tsx |
Routes mobile Paste action through terminal.paste() to preserve bracketed paste + newline normalization. |
src/components/shell/hooks/useShellTerminal.ts |
Updates paste key handling to avoid blocking native paste on environments without the async Clipboard API and to use terminal.paste() when available. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| (event.ctrlKey || event.metaKey) && | ||
| event.key?.toLowerCase() === 'v' | ||
| ) { | ||
| // Without the async clipboard API (common on self-hosted plain-http | ||
| // deployments, where navigator.clipboard doesn't exist) there is |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (1)
src/components/shell/hooks/useShellTerminal.ts:218
- The paste key handler still triggers on plain Ctrl+V (because it checks
event.ctrlKey || event.metaKey), which conflicts with the PR description/issue requirement that plain Ctrl+V should remain xterm's literal^Vand only Cmd+V / Ctrl+Shift+V should paste. This will cause Ctrl+V to paste (and be swallowed on denial) whenever the async clipboard API exists.
if (
event.type === 'keydown' &&
(event.ctrlKey || event.metaKey) &&
event.key?.toLowerCase() === 'v'
) {
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