fix(desktop): terminal selection copies from every entry point on macOS - #6483
fix(desktop): terminal selection copies from every entry point on macOS#6483realDragonium wants to merge 2 commits into
Conversation
Copy entry points each resolved against a different owner — the renderer shortcut handler, the native selection menu, and Electron's DOM-role context menu — and only the first could see the Ghostty selection. Route them all through one Ghostty-aware copy: the selection menu's Copy item carries the platform copy accelerator so Cmd+C works while the open menu owns the keyboard, right-click on a selection opens that same menu instead of the DOM-role one, menu dismissal refocuses the terminal input, and the clipboard write happens in the main process so it no longer depends on renderer document focus. Fixes pingdotgg#6173 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 73c5815. Configure here.
ApprovabilityVerdict: Needs human review This PR adds a new IPC channel for main-process clipboard writes, new accelerator support for context menus, and substantial new runtime behavior for terminal selection handling on macOS. While well-tested, the scope goes beyond a simple bug fix—it introduces new capabilities and changes how clipboard operations route on desktop. You can customize Macroscope's approvability policy. Learn more. |
…sses it A right-click that dismisses the open selection menu reaches the renderer before the menu's IPC resolution does, so the gesture ended menu-less: the contextmenu handler saw the menu still marked open and dropped the request. Park that pointer instead, and when the menu settles as a dismissal reopen at the parked position if the selection still exists. Any newer pointerdown anywhere in the window, or a window blur, clears the parked pointer so a long-delayed dismissal cannot reopen a menu the user has moved on from. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

What Changed
Terminal copying on macOS failed because each copy entry point resolved against a different owner, and only one of them could see the Ghostty selection (which lives in canvas/WASM state, not the DOM):
editFlags.canCopyis always false for a canvas selection, so Copy stayed disabled.navigator.clipboard.writeText, which Chromium rejects while the document is unfocused — and macOS shows context menus on inactive windows without activating them, so menu-driven copies could fail with an error even when everything upstream worked.All entry points now route through one Ghostty-aware copy:
Cmd+C/Ctrl+Shift+C), so pressing it while the open menu owns the keyboard activates Copy natively (ContextMenuItemgains an optionalaccelerator, forwarded byElectronMenu).desktop:write-clipboard-textIPC (LocalApi.clipboard.writeText), removing the document-focus dependency; browsers fall back tonavigator.clipboard.Ctrl+C without a selection stays SIGINT on every platform.
Why
Fixes #6173 — copying from the integrated terminal on macOS was broken enough to block work entirely (Cmd+C, the selection menu, and right-click Copy all failed in common flows).
UI Changes
Two visible deltas, both restoring expected behavior: the selection menu's Copy item now shows the ⌘C shortcut hint, and right-clicking a highlighted terminal selection shows the Add to chat / Copy menu instead of a generic menu with Copy disabled. Happy to attach screenshots on request.
Verification
Checklist
Implemented by Claude Fable 5 via Claude Code.
🤖 Generated with Claude Code
Note
Medium Risk
Touches terminal input encoding, IPC clipboard, and native menu keyboard handling—user-visible on macOS but scoped to selection/copy flows with broad test coverage.
Overview
Fixes macOS integrated-terminal copy by routing every copy path (keyboard shortcut, auto-open selection menu, right-click) through one Ghostty-aware
copySelectionTextthat writes viaLocalApi.clipboard.writeText— on desktop, a newdesktop:write-clipboard-textIPC to the main process so copies work when the renderer is unfocused (e.g. native context menus on inactive windows).Selection menu & native menus:
ContextMenuItemgains optionalaccelerator;ElectronMenuforwards non-empty accelerators so Cmd+C / Ctrl+Shift+C work while the menu tracks on macOS. The drawer shows Add to chat / Copy with platform chords, opens that menu on right-click when a Ghostty selection exists (not the generic DOM menu), reopens after dismiss-by-right-click, and refocuses the terminal after dismiss unless focus moved elsewhere.Terminal input hardening: macOS Ctrl+click (
button 0) no longer starts a new selection before context menu (isTerminalMacSecondaryClick). Key release to the PTY is only sent if that key’s press was encoded (encodedPressKeyCodes), avoiding release-only Kitty sequences when a native menu consumed the keydown.Contracts expose
acceleratoron context menu items andclipboard.writeText/ optionalwriteClipboardTexton desktop bridge; web falls back tonavigator.clipboard.Reviewed by Cursor Bugbot for commit 6ab350a. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Fix terminal selection copy on macOS by routing clipboard writes through the main process
writeClipboardTextIPC channel so the renderer can request clipboard writes via the Electron main process, working around renderer focus constraints that preventednavigator.clipboard.writeTextfrom succeeding on macOS.Cmd+Con macOS,Ctrl+Shift+Celsewhere), auto-reopen after right-click dismissal, and focus restoration to the terminal after dismissal.LocalApi.clipboard.writeTextprefersdesktopBridge.writeClipboardTexton desktop and falls back tonavigator.clipboardin the browser.Macroscope summarized 6ab350a.