Skip to content

fix(terminal): let unselected Cmd+C reach apps that own their selection - #23597

Merged
Jinwoo-H merged 5 commits into
mainfrom
fix/cmd-c-reaches-kitty-apps
Sep 28, 2026
Merged

Jinwoo-H merged 5 commits into
mainfrom
fix/cmd-c-reaches-kitty-apps

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​366 $\color{#cf222e}{\Huge{\mathbf{−}}}$​115 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​251
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​47 $\color{#cf222e}{\Huge{\mathbf{−}}}$​14 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​33

ELI5

In Codex's full-screen view, Codex draws its own text highlight, so Orca's terminal has nothing selected. Orca treated Cmd+C as "copy nothing", so Codex never received it and you couldn't copy. Now, when nothing is selected in the terminal and the app has asked for the richer keyboard protocol, Cmd+C goes to the app, and Codex copies its own highlight.

What Changed

Before: on macOS, Cmd+C always skipped xterm's keyboard encoder, even with no terminal selection. So apps that manage their own selection never received it.

After: Cmd+C is handed to the app when all three hold:

  • nothing is selected in xterm;
  • the app has enabled the Kitty keyboard protocol;
  • you're on macOS.

Otherwise nothing changes:

  • A terminal selection is copied exactly as before.
  • A plain shell still receives nothing.

Mechanism:

  • One rule, isAppOwnedCopyChord in xterm-bypass-policy.ts, is shared by the terminal pane and the dashboard popout. When it holds, the chord falls through to xterm's existing Kitty encoder and input transport.
  • The Kitty state comes from the pane's keyboard-mode mirror. fix(terminal): stop guessing that apps died and wiping their keyboard modes #23584 made that mirror always agree with xterm, and makes it report "off" where the protocol isn't offered (Windows ConPTY). That's what makes the rule reliable after Ctrl+C and reconnects.
  • A Cmd+C that copies a selection now stays claimed through key repeat and release, including custom copy bindings, so neither leaks to the app.

Why

  • Why an app-negotiated signal: Codex's highlight isn't an xterm selection, so Orca can't copy it; only the app can. The Kitty protocol is how an app announces it wants modified keys, so it's the right signal, with no app detection and no hardcoded bytes.
  • Why this was parked: the rule was previously unsafe because Orca wiped the app's keyboard mode on every Ctrl+C. It depends on fix(terminal): stop guessing that apps died and wiping their keyboard modes #23584, which removes that guess.
  • How other terminals behave: one leaks a stray c into TUIs on an unselected Cmd+C, and another swallows it. Neither lets the app copy.
  • Linux and Windows: there's no observable change. Copy is Ctrl+Shift+C there, and an unselected Ctrl+C already reaches the app as an interrupt.

Linked Issue

Related to #9727. This supersedes #22950, re-derived on top of #23584.

Visual Proof

N/A: this is a keyboard delivery change. The e2e test reads the exact bytes the app receives.

Testing

  • Automated tests added/updated
  • I manually tested these changes locally

e2e (terminal-shortcuts.spec.ts, macOS): a new test, "unselected Cmd+C reaches a Kitty app, including after Ctrl+C", covers four cases:

  • a plain shell receives nothing;
  • a Kitty app receives \x1b[99;9;99u / \x1b[99;9:3u;
  • with a selection, Cmd+C copies and sends nothing;
  • after Ctrl+C the app keeps its flags and still receives Cmd+C.

It fails with the fix reverted.

Unit:

  • the predicate across flag values, selection state, Shift and non-mac;
  • copy dispatch with held and remapped bindings;
  • the popout: plain shell, a Kitty app, a selection, and a selection of blank cells only.

Results:

  • 4,926 terminal-pane and dashboard-popout tests pass.
  • The terminal-shortcuts and reattach-parity specs: 10 passed, 2 skipped (Windows-only).

Not covered by automation: CDP-injected keys have no native macOS key event, so the automated tests can't check how a real key press interacts with Edit→Copy. From Electron's key handling, the renderer sees Cmd+C before the menu does. Please press Cmd+C once in Codex before merging.

Review

Edge cases:

  • If the selection is cleared while Cmd+C is held, later repeats reach the app.
  • A Kitty app that doesn't bind Cmd+C receives one harmless extra key.

Stacked PR: this is based on #23584. Review and merge that first.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • App-owned Cmd+C predicate — new isAppOwnedCopyChord in xterm-bypass-policy.ts: macOS only, no terminal selection, Kitty flags non-zero, and a Mod+C match. shouldBypassXtermKeyboardEvent now returns false for it (letting xterm's Kitty encoder deliver the chord to the app), placed after the defaultPrevented early-return so an already-claimed chord still bubbles.
  • Popout parity — preview-terminal-key-handler.ts applies the same rule to the dashboard popout, so an unselected Cmd+C falls through to xterm instead of being consumed; selection and plain-shell paths are unchanged.
  • Held-copy claim — resolveTerminalShortcutAction now resolves copySelection on repeat, and dispatchTerminalShortcutAction claims copy keydowns before the event.repeat guard, arming the native-only tracker and copying only on the first keydown — so a held copy no longer leaks repeat/release CSI-u into a Kitty app.
  • Tests — new unit tests for the predicate, the popout copy dispatch, and repeat/custom-binding resolution; the mac-only e2e covers plain shell, Kitty app, selection, after-Ctrl+C, and flags-cleared. E2E keyboard helpers were split into tests/e2e/helpers/terminal-kitty-keyboard.ts.

Verification: the 6 changed/relevant unit suites pass (114 tests) and oxlint is clean on the 7 changed files. The one thing automation cannot exercise — whether a real macOS key press reaches the renderer before the Edit→Copy menu accelerator — is already called out in the PR body as a manual pre-merge check; merging depends on #23584 first, as the PR notes.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

…keyboard

On macOS Orca swallowed an unselected Cmd+C as a no-op copy, so a full-screen
TUI like Codex, which captures the mouse and keeps its highlight out of xterm's
selection, never received its own copy chord.

- isAppOwnedCopyChord (xterm-bypass-policy) is the one rule: macOS, no xterm
  selection, and non-zero kitty flags from the pane's mirror. The pane's xterm
  bypass and the dashboard popout's key handler both use it.
- A selection copy stays claimed through its repeats and release, including
  custom copy bindings, so kitty event reporting cannot leak them to the PTY.
- Plain shells keep sending nothing; Linux and Windows are unchanged.
- The e2e kitty helpers move to helpers/terminal-kitty-keyboard.ts so the
  shortcut spec stays under the line limit.
… pane

A highlight of blank cells trims to empty text but is still a selection, so the
popout must not hand that Cmd+C to a kitty app while the pane withholds it.
…tch tests

The shortcut-policy suite is at its line limit.
@Jinwoo-H
Jinwoo-H force-pushed the fix/cmd-c-reaches-kitty-apps branch from 28d38f2 to 35fceda Compare September 28, 2026 19:23
@Jinwoo-H
Jinwoo-H changed the base branch from feat/terminal-stops-guessing-input-modes to main September 28, 2026 19:23
@coderabbitai

coderabbitai Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 2fab7f53-3c49-4db0-9bbf-13d0a268519b

📥 Commits

Reviewing files that changed from the base of the PR and between 3eac4d9 and 35fceda.

📒 Files selected for processing (11)
  • src/renderer/src/components/dashboard-popout/AgentTerminalPreview.clipboard-routes.test.tsx
  • src/renderer/src/components/dashboard-popout/AgentTerminalPreview.option-dead-key.test.tsx
  • src/renderer/src/components/dashboard-popout/AgentTerminalPreview.test.tsx
  • src/renderer/src/components/dashboard-popout/preview-terminal-key-handler.ts
  • src/renderer/src/components/terminal-pane/terminal-copy-shortcut.test.ts
  • src/renderer/src/components/terminal-pane/terminal-keyboard-action-dispatch.ts
  • src/renderer/src/components/terminal-pane/terminal-shortcut-policy.ts
  • src/renderer/src/components/terminal-pane/xterm-bypass-policy.test.ts
  • src/renderer/src/components/terminal-pane/xterm-bypass-policy.ts
  • tests/e2e/helpers/terminal-kitty-keyboard.ts
  • tests/e2e/terminal-shortcuts.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The terminal copy routing now accounts for macOS Cmd+C, terminal selection state, and active Kitty keyboard flags. Repeated copy keydowns continue through shortcut dispatch without repeating clipboard writes. Unit and end-to-end tests cover copy routing, repeated shortcuts, and Kitty keyboard reporting.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 35fce

The change is mergeable after normal checks. Complete the requested native macOS Cmd+C check to confirm that Edit→Copy does not interfere with app-owned input.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 35fce

The new routing is limited to an explicit macOS copy shortcut when there is no terminal selection and the application has enabled the keyboard protocol. A narrow transition remains: if the selection disappears while the key is held, later key events may be split between the terminal and the application. No broader security exposure was established.

Retained concerns

  • Low · architecture · inferred: If selection clears between an initially claimed Cmd+C and its repeats, the new app-owned route can deliver repeat keydowns to the PTY application while terminal-side claim state still consumes keyup. One physical gesture may therefore have two owners, leaving an application that tracks releases with an unmatched key event.
Security review details

Security Blast Radius

  • inferred — The new input exposure is confined to the active Kitty-enabled terminal session after a user Cmd+C, rather than granting the PTY application a general clipboard or cross-pane input capability.

Trust Boundaries and Controls

  • observed — Terminal output can negotiate Kitty keyboard mode, but the forwarding decision also checks live flags, platform, chord, and selection. Preview input then uses the existing xterm-to-PTY transport.

Resilience and Maintainability Implications

  • inferred — The held-key selection transition is an input-ownership gap, not evidence of a credential, clipboard-read, or privilege escalation path. Its application-visible effect depends on how the negotiated application handles repeat and release events.

Hardening Proposals

  • proposed — Keep ownership of one physical copy gesture consistent through repeats and release, and cover selection changes while the key is held in both terminal surfaces.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 11 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: allowing unselected macOS Cmd+C events to reach applications that manage their own selection.
Description check ✅ Passed The description is complete and aligned with the template. It explains the user impact, implementation, rationale, linked issues, testing, platform considerations, limitations, and checklist status. I…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant