Skip to content

Copy the terminal selection with Ctrl+Shift+C - #5380

Merged
ymichael merged 2 commits into
get-bb:mainfrom
dyc3:dyc3/fix-it-so-that-copy-and-paste-works-in-terminal-thr_nfdz2rvy64
Oct 14, 2026
Merged

ymichael merged 2 commits into
get-bb:mainfrom
dyc3:dyc3/fix-it-so-that-copy-and-paste-works-in-terminal-thr_nfdz2rvy64

Conversation

@dyc3

@dyc3 dyc3 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Human comments

Paste already works. Copying text out of the terminal is the issue.

I'm not too good with react, so I don't really know if the clanker got this right. It's an issue I encounter regularly, and I figured I'd send a PR for it.

I had my other clanker test it on a mac with computer use.

What was wrong

xterm.js has no copy keyboard shortcut of its own. It copies only when the browser fires a native copy event, which it then fills with the terminal selection (CoreBrowserTerminal's copy listener). On macOS, Cmd+C fires that event, so copying already worked. On Linux and Windows the native copy key is Ctrl+C, which xterm sends to the shell as an interrupt and cancels, and Ctrl+Shift+C, the usual terminal copy key, reaches nothing: xterm's Ctrl+letter mapping skips Shift, and Chrome treats it as the DevTools inspector shortcut. So the terminal had no way to copy from the keyboard there. Ctrl+Shift+V already pasted through the native paste event. See #3341.

What changed

  • apps/app/src/components/thread/terminal/terminal-copy-shortcut.ts (new): an xterm custom key handler for Ctrl+Shift+C. It copies the terminal selection through the existing copyToClipboardWithToast helper, silently on success and with "Failed to copy" on error, and claims the key (prevents default and stops propagation) so the browser and app shortcuts don't also act on it. With no selection it does nothing. The key is matched by key, falling back to code on non-Latin layouts.
  • ThreadTerminalView.tsx attaches the handler when the terminal mounts, on every platform. On macOS, Ctrl+Shift+C previously did nothing, and Cmd+C never reaches the handler, so it keeps using the browser's native copy.
  • Ctrl+C still sends an interrupt, with or without a selection. Paste is unchanged.

Compared with the first revision of this PR, the handler no longer takes over Cmd+C on macOS or the paste chords, since both already worked natively.

No wire, CLI, or documentation changes.

How you verified

  • terminal-copy-shortcut.test.ts dispatches key events at a real xterm instance: Ctrl+Shift+C copies the selection on Latin and non-Latin layouts without sending input, an empty selection copies nothing, and Ctrl+C with a selection still sends \x03. With the handler removed, the copy tests fail.
  • pnpm exec turbo run test --filter=@bb/app -- src/components/thread/terminal: 8 files, 53 tests pass.
  • pnpm exec turbo run typecheck lint --filter=@bb/app: 0 errors.
  • pnpm start:worktree build driven in Chromium on macOS against a live zsh terminal, selecting echoed output and reading the clipboard:
    • Before (main, Linux platform emulated): Ctrl+Shift+C left the clipboard unchanged.
    • After, Linux emulated: Ctrl+Shift+C copied the selection.
    • After, macOS: Cmd+C copied through the native copy event, as on main; Ctrl+Shift+C also copied; Cmd+V pasted once.
    • With text selected, Ctrl+C interrupted a running sleep 300 (exit 130) and left the clipboard unchanged.
  • Not run: real Linux or Windows browsers, the Electron desktop app on Linux or Windows, and Firefox. Linux behavior was checked by emulating the platform in Chromium on macOS, which cannot show whether real Chrome on Linux lets the page take Ctrl+Shift+C ahead of DevTools.

Fixes #3341

🤖 Generated with Claude Code

AGENT GENERATED

@github-actions

Copy link
Copy Markdown
Contributor

Thanks @dyc3 for the PR. This repo needs approval before a PR. Join the #contributors channel in Discord (https://discord.gg/kvBU6tJhcJ) and explain what you want to open a PR for and why. A maintainer then adds you to the allow list. This PR now closes on its own. Reopen it or open a new one after approval.

@github-actions github-actions Bot closed this Oct 12, 2026
xterm.js has no copy shortcut of its own. It copies only through the
browser's native copy event, which Cmd+C fires on macOS. On Linux and
Windows the native shortcut is Ctrl+C, which the terminal sends as an
interrupt, and Ctrl+Shift+C reaches nothing. Ctrl+Shift+V already pastes
through the native paste event, so only Ctrl+Shift+C needs handling.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael

Copy link
Copy Markdown
Collaborator

/approve @dyc3

@github-actions

Copy link
Copy Markdown
Contributor

Approved @dyc3 for PRs. The name now stays on the allow list. The author can open a PR now.

@ymichael ymichael reopened this Oct 14, 2026
@ymichael ymichael changed the title Copy the terminal selection with Ctrl+Shift+C and Cmd+C Copy the terminal selection with Ctrl+Shift+C Oct 14, 2026
@ymichael
ymichael marked this pull request as ready for review October 14, 2026 22:59
@ymichael
ymichael merged commit b8e312a into get-bb:main Oct 14, 2026
26 checks passed
@dyc3
dyc3 deleted the dyc3/fix-it-so-that-copy-and-paste-works-in-terminal-thr_nfdz2rvy64 branch October 14, 2026 23:07
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.

Support copy-and-paste keyboard shortcuts in the integrated terminal

2 participants