Skip to content

fix(terminal): deliver Ctrl+C when a non-Latin input source rewrites the key - #14462

Merged
nwparker merged 1 commit into
mainfrom
nwparker/ctrl-c-non-latin-layout
Aug 14, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/ctrl-c-non-latin-layout

Conversation

@nwparker

@nwparker nwparker commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #14460. Builds on @hgijeon's diagnosis and their patch in #14430 — same root cause, widened, with a hardware measurement that changes the conclusion.

Where it came from

isTerminalInterruptCKey was introduced by #3941 (65cab0f5da1, "fix terminal kitty recovery for codex"). That PR added the ETX bypass so Ctrl+C would stop being CSI-u encoded for Codex — a real fix — but matched the logical key against c, which only holds for Latin layouts.

The bypass exists because #1247 (eb92ba9448c) advertises the kitty keyboard protocol. With kitty active and no bypass, Ctrl+C is CSI-u encoded and never becomes ETX. So a non-Latin input source has fallen through since #3941: the bypass that rescues Latin users does not recognise the key.

Reproduced

Confirmed from the code path, not just the report:

const normalizedKey = event.key.toLowerCase()          // 'ㅊ' under Korean 2-Set
const logicalKeyAvailable = normalizedKey !== '' && normalizedKey !== 'unidentified'  // true
return logicalKeyAvailable ? normalizedKey === 'c' : event.code === 'KeyC' || ...     // false

The code fallback only ran when key was empty or Unidentified. A Hangul jamo is neither, so it short-circuited to false and the press missed the ETX path.

Four new cases fail on unmodified main. Not Korean-only — Russian and Greek fail identically.

Measured on hardware

macOS, via UCKeyTranslate over each installed layout (virtual keycode 8 = physical C):

layout KeyC produces
com.apple.keylayout.ABC c U+0063
com.apple.keylayout.2SetHangul ㅊ U+314A
com.apple.keylayout.Russian с U+0441
com.apple.keylayout.ABC-AZERTY / -QWERTZ c U+0063

Korean 2-Set is a keyboard layout, not an IME layered over QWERTY. Its KeyC genuinely maps to ㅊ at the OS level. That is why key arrives as a jamo, and it means a fix that asks the layout for the base character gets ㅊ back, not c.

The rule

  1. key is a Latin letter → authoritative. A Dvorak remap of C keeps working (existing test pins key: "j" as not-an-interrupt).
  2. Otherwise consult the layout map. An IME layered over a Latin layout answers c; over a Dvorak base it answers j and correctly declines.
  3. The map is itself non-Latin, or unavailable → fall back to physical position, which is how terminals have always resolved control chords.

Given the measurement, Korean 2-Set is resolved by tier 3, not tier 2. Tier 2 is still worth keeping: it is what makes a genuine IME-over-Latin source precise rather than merely positional, and it is @hgijeon's idea from #14430.

The important property is that the fix does not depend on which tier fires — both return the same answer here.

On #14430

Their patch resolves a non-ASCII key through the layout map and then still compares the result against c. Against the measured 2SetHangul layout that comparison is 'ㅊ' === 'c', which is false, so the interrupt would still be swallowed. Their unit test passes because it stubs the map with [['KeyC', 'c']].

Caveat on that claim: my measurement is of the OS layout via UCKeyTranslate. Our module reads Chromium's navigator.keyboard.getLayoutMap(), and I have not measured Chromium's answer under a live Korean input source — if Chromium substitutes an ASCII-capable layout there, #14430 would work and tier 2 would fire instead. Tier 3 makes that difference immaterial here.

Tests

xterm-bypass-policy-interrupt.test.ts, +7 cases:

  • Ctrl+C with a non-Latin key (Korean jamo, Cyrillic, Greek, Hangul syllable) → interrupt
  • the matching keyup is suppressed, so no release leaks after the interrupt
  • Dvorak key: "j" on KeyC → still not an interrupt
  • non-Latin key on a physical key other than KeyC → not an interrupt
  • layout map says c → interrupt; says j → declines; is itself non-Latin → positional fallback

Verified on real hosts at this exact commit, not just locally:

  • Windows — 268 files / 3433 passed, 1 skipped
  • macOS — 268 files / 3433 passed, 1 skipped

Typecheck clean.

Not verified

No live end-to-end run with the Korean input source active driving a real TUI. The layout data above is measured; the browser-level event shape comes from @hgijeon's report and their before/after recordings in #14430.

Credit

@hgijeon reported this with a correct root-cause diagnosis, the measured event shape, a working patch, and before/after recordings against the real Codex CLI.

…the key

With a non-Latin input source the OS reports the layout's own glyph for `key` —
a Hangul jamo on Korean 2-Set, Cyrillic es on Russian — while `code` stays KeyC.
The interrupt policy read `key` for identity and only consulted `code` when
`key` was empty or Unidentified, so a jamo short-circuited it to false: the
press missed the ETX path and was CSI-u encoded instead, leaving a TUI running.

Trust `key` only when it is a Latin letter, which keeps a Dvorak remap of C
authoritative. Otherwise ask the layout map what the physical key produces
unmodified: an IME layered over a Latin layout answers 'c', and over a Dvorak
base answers 'j', which correctly declines. When the map is itself non-Latin it
cannot answer either, so fall back to physical position — how terminals have
always resolved control chords.

Fixes #14460
@coderabbitai

coderabbitai Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Interrupt-key detection now distinguishes Latin logical keys from non-Latin input-source glyphs. It uses the physical key’s layout mapping when available and retains physical KeyC or keyCode fallback behavior when no Latin mapping exists. Tests reset the layout map between cases and cover remapped layouts, IMEs, non-Latin keys, matching keyup suppression, and non-KeyC physical keys.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the root cause, implementation, linked issue, tests, and limitations, but it omits required template sections and visual proof. Add the required template sections, complete the testing and checklist items, and attach before/after recordings or screenshots for this behavior change.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes meet issue #14460 by delivering Ctrl+C interrupts for rewritten non-Latin keyboard events while preserving remapped layouts.
Out of Scope Changes check ✅ Passed The code and tests remain focused on Ctrl+C interrupt detection, layout handling, and related non-Latin keyboard cases.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title clearly identifies the terminal Ctrl+C fix for non-Latin input sources.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
src/renderer/src/components/terminal-pane/xterm-bypass-policy-interrupt.test.ts (1)

110-114: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Condense the test comments.

The test names and assertions already state most of this behavior. Keep only short comments for the non-obvious invariant.

As per coding guidelines, “Comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior or walk through code.”

Also applies to: 137-138, 148-148, 158-159, 170-171, 182-183

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 29e9f46c-3b55-4a70-8a20-f8fea78d6169

📥 Commits

Reviewing files that changed from the base of the PR and between 77f23b0 and 3a9f9ab.

📒 Files selected for processing (2)
  • src/renderer/src/components/terminal-pane/xterm-bypass-policy-interrupt.test.ts
  • src/renderer/src/components/terminal-pane/xterm-bypass-policy.ts

@nwparker
nwparker merged commit e2e7768 into main Aug 14, 2026
45 checks passed
@nwparker
nwparker deleted the nwparker/ctrl-c-non-latin-layout branch August 14, 2026 06:18
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…the key (stablyai#14462)

With a non-Latin input source the OS reports the layout's own glyph for `key` —
a Hangul jamo on Korean 2-Set, Cyrillic es on Russian — while `code` stays KeyC.
The interrupt policy read `key` for identity and only consulted `code` when
`key` was empty or Unidentified, so a jamo short-circuited it to false: the
press missed the ETX path and was CSI-u encoded instead, leaving a TUI running.

Trust `key` only when it is a Latin letter, which keeps a Dvorak remap of C
authoritative. Otherwise ask the layout map what the physical key produces
unmodified: an IME layered over a Latin layout answers 'c', and over a Dvorak
base answers 'j', which correctly declines. When the map is itself non-Latin it
cannot answer either, so fall back to physical position — how terminals have
always resolved control chords.

Fixes stablyai#14460
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.

[Bug]: Ctrl+C is swallowed with macOS Korean 2-Set input

1 participant