Repository navigation
fix(terminal): resolve Ctrl chords positionally on a non-Latin layout - #14469
Conversation
macOS maps a control chord by physical key regardless of layout: measured with UCKeyTranslate, physical A/U under Control produce U+0001/U+0015 on 2SetHangul, Russian and Greek exactly as on ABC, though unmodified those keys give ㅁ/ㅕ, ф/г, α/θ. A native terminal inherits this by passing the OS characters through. The browser does not expose that translation. xterm's legacy encoder works anyway because it reads keyCode, which Chromium reports from the physical key, but its kitty encoder derives the key number from `key` and only consults `code` when Shift or Option is held. Ctrl is not in that gate, so a pane with the kitty protocol negotiated reports CSI-u for U+3141 rather than 'a' and the chord does nothing. Ctrl+C escaped this only via its hand-written ETX bypass. Recover the byte from `code` when `key` is non-ASCII, which reproduces the OS control table. An ASCII `key` stays authoritative so a Dvorak remap is honoured. KeyC is excluded: the interrupt policy owns it, and off macOS that policy declines to a selection so the copy binding wins. Fixes #13331
📝 WalkthroughWalkthroughThe change adds handling for non-ASCII Ctrl+letter keyboard events. It derives control bytes from physical letter keys, excludes unsupported combinations, and matches claimed keyups. Terminal lifecycle processing tracks the claimed key code, sends resolved input, suppresses the matching keyup, and updates Linux IME candidate-event state. Tests cover supported layouts, rejected events, mappings, and keyup behavior. Merge Risk: 🟡 Moderate · up to The change can incorrectly handle overlapping non-Latin Ctrl chords: an earlier key release may be forwarded to the terminal and produce an unintended kitty release report. Merge readiness therefore depends on tracking all claimed physical keys or explicitly accepting this bounded input-handling risk. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/renderer/src/components/terminal-pane/terminal-non-latin-control-chord.ts (1)
1-18: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueKeep implementation comments brief.
Reduce these comments to the non-obvious rationale. Keep the issue reference where needed. Move browser and xterm behavior details to linked documentation if they must be retained.
src/renderer/src/components/terminal-pane/terminal-non-latin-control-chord.ts#L1-L18: replace the long behavior description with a short statement of the physical-key translation rationale.src/renderer/src/components/terminal-pane/terminal-non-latin-control-chord.ts#L29-L37: reduce theKeyCpolicy explanation to its ownership boundary.src/renderer/src/components/terminal-pane/terminal-non-latin-control-chord.ts#L59-L64: retain only the Shift exclusion rationale.src/renderer/src/components/terminal-pane/terminal-non-latin-control-chord.test.ts#L21-L23: keep only the layout-coverage purpose.src/renderer/src/components/terminal-pane/terminal-non-latin-control-chord.test.ts#L48-L49: keep only the Ctrl+C ownership rationale.src/renderer/src/components/terminal-pane/terminal-non-latin-control-chord.test.ts#L83-L86: keep only the non-ASCII rule rationale.src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts#L1087-L1090: retain only the ordering rationale.As per coding guidelines: “Comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior.”
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 7f460332-9b01-4270-b807-298630e82dcb
📒 Files selected for processing (3)
src/renderer/src/components/terminal-pane/terminal-non-latin-control-chord.test.tssrc/renderer/src/components/terminal-pane/terminal-non-latin-control-chord.tssrc/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts
|
|
||
| // Why: let host-handled keys bypass xterm's kitty CSI-u encoder — with kittyKeyboard on it preventDefaults Cmd+C and blocks Chromium's native copy. See xterm-bypass-policy.ts. | ||
| let pendingTerminalInterruptKeyup = false | ||
| let claimedNonLatinControlChordCode: string | null = null |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Track all claimed physical keys.
Line 989 stores only one claimed code. A second non-Latin Ctrl chord can overwrite the first code before its keyup arrives. The first keyup then reaches xterm and can emit the kitty release report that this flow must suppress.
Store claimed codes in a Set<string>. Remove only the matching code on keyup. Update isNonLatinControlChordKeyup and its tests to accept multiple claimed codes.
Proposed fix
- let claimedNonLatinControlChordCode: string | null = null
+ const claimedNonLatinControlChordCodes = new Set<string>()
- if (isNonLatinControlChordKeyup(e, claimedNonLatinControlChordCode)) {
- claimedNonLatinControlChordCode = null
+ if (isNonLatinControlChordKeyup(e, claimedNonLatinControlChordCodes)) {
+ claimedNonLatinControlChordCodes.delete(e.code)
observeLinuxCandidateEvent()
return false
}
const nonLatinControlChord = resolveNonLatinControlChordInput(e)
if (nonLatinControlChord) {
- claimedNonLatinControlChordCode = e.code
+ claimedNonLatinControlChordCodes.add(e.code)
pane.terminal.input(nonLatinControlChord)- claimedCode: string | null
+ claimedCodes: ReadonlySet<string>
- if (event.type !== 'keyup' || !claimedCode) {
+ if (event.type !== 'keyup' || !event.code) {
return false
}
- return event.code === claimedCode
+ return claimedCodes.has(event.code)Also applies to: 1091-1102
…stablyai#14469) macOS maps a control chord by physical key regardless of layout: measured with UCKeyTranslate, physical A/U under Control produce U+0001/U+0015 on 2SetHangul, Russian and Greek exactly as on ABC, though unmodified those keys give ㅁ/ㅕ, ф/г, α/θ. A native terminal inherits this by passing the OS characters through. The browser does not expose that translation. xterm's legacy encoder works anyway because it reads keyCode, which Chromium reports from the physical key, but its kitty encoder derives the key number from `key` and only consults `code` when Shift or Option is held. Ctrl is not in that gate, so a pane with the kitty protocol negotiated reports CSI-u for U+3141 rather than 'a' and the chord does nothing. Ctrl+C escaped this only via its hand-written ETX bypass. Recover the byte from `code` when `key` is non-ASCII, which reproduces the OS control table. An ASCII `key` stays authoritative so a Dvorak remap is honoured. KeyC is excluded: the interrupt policy owns it, and off macOS that policy declines to a selection so the copy binding wins. Fixes stablyai#13331
Fixes #13331. Generalises the Ctrl+C fix from #14462 to the rest of the control chords, and grounds it in a measurement of what macOS itself does.
What the platform does
Measured on real hardware with
UCKeyTranslate, per layout, at the physical A/U/C keys:keylayout.ABCaukeylayout.2SetHangulㅁㅕkeylayout.Russianфгkeylayout.GreekαθmacOS resolves a control chord by physical key, on every layout. The
.keylayoutfiles carry ananyControltable that produces the C0 byte regardless of what the key types unmodified.A native terminal inherits this for free — it reads the OS-provided characters and passes them through. I checked a reference implementation's source: it has no ASCII-capable-layout fallback and no virtual-keycode table anywhere. Its control-byte rule is
charactersIgnoringModifiersin'a'..'z', and when that misses — which is exactly the non-Latin case — it writes the OS's bytes verbatim. Ctrl+C works there on Russian because Apple's layout says U+0003, not because the terminal does anything layout-aware.So positional resolution is the platform-correct answer, and matching it is matching every native terminal.
Why we do not get it for free
The browser does not expose that translation.
KeyboardEvent.keycarries the layout glyph (ㅁ), and nothing surfaces the OS's control byte.xterm's legacy encoder is fine — it reads
keyCode(65–90), which Chromium reports from the physical key, so control chords already work when the kitty protocol is off.xterm's kitty encoder is not. It derives the key number from
ev.key, and only consultsev.codewhen Shift or Option is held:So a pane with kitty negotiated reports
CSI 12609;5uinstead ofCSI 97;5u, and the chord does nothing. That is #13331, and it is why #3941 needed a hand-written ETX bypass for Ctrl+C in the first place — Ctrl+C was the one letter someone had already rescued.The rule
When Ctrl is held alone and
keyis a single non-ASCII codepoint, recover the letter fromcodeand send the C0 byte — reproducing the OS control table.keystays authoritative, so a Dvorak remap is honoured.KeyCis excluded. The interrupt policy owns it: off macOS it must yield to a selection so the copy binding wins, and it resets the pane's kitty flags because a CLI can die on SIGINT before restoring them. Claiming C here would have sent ETX in exactly the case that policy deliberately declines — a regression I caught while wiring this up, and the reason the exclusion is explicit rather than incidental.keyon these layouts, so xterm already sees them correctly.A note on kitty and the reference implementation
Under the kitty protocol that reference terminal reports the layout codepoint too — its modern mapper re-translates through the current layout, so Ctrl+C on Russian yields
CSI 1089;5u. We deliberately do not match that: it is the broken behaviour this issue is about. We match its legacy path, which is the one that works, and which agrees with the OS.Tests
New
terminal-non-latin-control-chord.test.ts, 16 cases, driven by the measured table above:key(DvorakjonKeyC) → untouchedKeyC→ left to the interrupt policyProcess, emptykey→ untouchedVerified at this exact commit:
Not verified
No live end-to-end run with a Korean input source driving a TUI. The layout data is measured; the browser-level event shape comes from the #13331 and #14460 reports.