fix(terminal): copy selected text to clipboard automatically - #101
Conversation
Right-click on a terminal pane never offered "Copy" — xterm.js clears the text selection on the right mousedown before the browser's context menu opens, and Ctrl+C is unavailable for copying since it's sent through as SIGINT to the running process instead. The only way out was selecting then relying on Ctrl+C, which just killed whatever CLI was running. xterm v4's copyOnSelect option was removed upstream; the replacement is wiring onSelectionChange() ourselves. Copy the selection to the clipboard (via the existing copyText() helper, which already falls back to execCommand for non-secure-context/tunnel use) as soon as one is made, matching how most terminal apps behave. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011E2bJQ2sL9LgEWosjvydTR
…change xterm fires onSelectionChange from the selection service's refresh on every animation frame while the mouse is still dragging, so the previous wiring was a clipboard write per frame — and over plain http copyText() falls back to a focused off-screen textarea, which stole focus from the pane mid-drag. The existing mouseup handler already knows whether a selection was dragged out; the copy now happens there, once, when the drag ends. test/composer-terminal.test.js pins the new shape and asserts that term.onSelectionChange is not used. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Thanks — right diagnosis, and One change, pushed to your
|
Summary
Right-click on a terminal pane never offered "Copy" — xterm.js clears the text selection on the right mousedown before the browser's context menu opens, and Ctrl+C can't be repurposed for copying since it's already sent through as SIGINT to whatever's running in the pane. In practice there was no way to copy terminal output at all short of it being echoed elsewhere.
xterm v4's
copyOnSelectoption was removed upstream; the documented replacement is wiringonSelectionChange()yourself. This copies the selection to the clipboard (via the existingcopyText()helper, which already falls back toexecCommandfor non-secure-context/tunnel use) the moment a selection is made, matching how most terminal apps behave.Test plan
🤖 Generated with Claude Code
https://claude.ai/code/session_011E2bJQ2sL9LgEWosjvydTR