Skip to content

fix(terminal): deliver Korean-layout Ctrl-C to TUIs - #14430

Closed
hgijeon wants to merge 1 commit into
stablyai:mainfrom
hgijeon:fix/terminal-ctrl-c-korean-ime
Closed

hgijeon wants to merge 1 commit into
stablyai:mainfrom
hgijeon:fix/terminal-ctrl-c-korean-ime

Conversation

@hgijeon

@hgijeon hgijeon commented Aug 14, 2026 •

Copy link
Copy Markdown

ELI5

With the macOS Korean 2-Set input source active, Electron reports the physical C key as a Hangul character instead of c. Orca therefore missed Ctrl+C and Codex stayed open after repeated interrupt attempts. This patch uses Orca's existing keyboard-layout map to recognize that key as C and deliver the normal terminal interrupt.

What Changed

  • Resolve a single non-ASCII event.key through the existing KeyboardLayoutMap cache when checking for Ctrl+C.
  • Prefetch that cache where the xterm key handler is installed.
  • Apply the same decision to keydown and keyup so Kitty release sequences cannot leak after the interrupt.

The patch intentionally remains Ctrl+C-specific. It does not introduce another general shortcut state machine or change terminal/session restoration.

Why

The measured macOS Korean 2-Set event is key: "ㅊ", code: "KeyC", with Ctrl held. Matching only logical c misses it, while treating every physical KeyC as C would break layouts such as Dvorak.

Orca already caches Chromium's layout-aware base character for a physical code. Consulting that cache only when key is one non-ASCII printable character fixes the measured event while leaving ASCII logical keys authoritative and preserving the existing platform and clipboard policies.

Linked Issue

Fixes #14460

Related: #13331 reports Ctrl+A and Ctrl+U under the same input source; those broader chords are deliberately outside this focused patch.

Visual Proof

Both recordings use the same isolated Orca E2E profile, the real Codex CLI, and the measured Korean 2-Set event shape. The terminal is cropped and enlarged, and the two Ctrl+C presses share the same timeline for direct comparison.

Before: both Ctrl+C presses are swallowed and Codex remains open.

Before: Korean Ctrl+C is swallowed

After: ETX reaches the terminal and Codex returns to the shell.

After: Korean Ctrl+C returns to the shell

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Revalidated on macOS:

  • corepack pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/terminal-pane/xterm-bypass-policy-interrupt.test.ts src/renderer/src/components/terminal-pane/xterm-bypass-policy-non-mac.test.ts src/renderer/src/lib/keyboard-layout/layout-base-character.test.ts
  • corepack pnpm run typecheck
  • Headful Electron Before/After run with the real Codex CLI

The targeted tests cover the Korean event shape, Dvorak logical-key precedence, keyup suppression, unavailable layout maps, and unchanged Windows/Linux Ctrl+C selection behavior. The earlier full local validation also covered lint, production builds, and the macOS native build; CI will repeat the repository-wide checks.

Actually exercised on macOS with Korean 2-Set. Linux and Windows were not manually exercised; their unchanged branches are covered by the non-macOS policy tests.

AI Disclosure

OpenAI Codex was used for diagnosis, implementation, tests, recording preparation, and PR drafting. The keyboard event and final behavior were also verified in the running Electron app.

Review

  • Security: No new IPC, dependencies, persisted data, command execution, or credential handling.
  • Cross-platform: Existing Windows/Linux selection semantics remain unchanged: Ctrl+C copies with a selection and interrupts otherwise.
  • Alternative layouts: An ASCII logical key wins over the physical code, preserving Dvorak and similar layouts.
  • Remote SSH: Classification occurs before terminal transport selection, so local and remote PTYs receive the same ETX.
  • Mobile: No mobile input path changes.
  • Compatibility/performance: The existing synchronous cache and idempotent prefetch are reused; no asynchronous work is added per keystroke.

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • 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)

Author

Electron reports the physical C key as the Hangul jamo ㅊ while the Korean input source is active. Resolve that non-ASCII key through the existing KeyboardLayoutMap cache before deciding whether xterm should forward ETX, while preserving logical-layout behavior such as Dvorak.
@coderabbitai

coderabbitai Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: dc2ed36f-e26e-4b83-88cd-3308bd87f5dd

📥 Commits

Reviewing files that changed from the base of the PR and between 8c3a119 and 6627400.

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

📝 Walkthrough

Walkthrough

Terminal pane creation now prefetches keyboard layout base characters before IME setup. Terminal interrupt detection maps single non-ASCII printable keys through their physical key codes before checking for c. Tests reset the layout map after each case and verify Korean-layout Ctrl+C recognition and keyup suppression.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 identifies the primary change: fixing Ctrl+C delivery under the Korean keyboard layout.
Description check ✅ Passed The description follows the template and clearly documents the change, rationale, issue reference, visual proof, testing, AI use, review considerations, and checklist.

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.

@hgijeon

hgijeon commented Aug 14, 2026

Copy link
Copy Markdown
Author

Closing for now while the fix is redesigned around a general, cross-platform IME Ctrl+letter normalization path and clearer visual proof.

@hgijeon hgijeon closed this Aug 14, 2026
@hgijeon hgijeon reopened this Aug 14, 2026
@hgijeon

hgijeon commented Aug 14, 2026

Copy link
Copy Markdown
Author

Reopened after the broader Ctrl-letter design review. The generalized local experiment exposed overlap with the existing physical-key ownership/release machinery and would widen this fix unnecessarily, so the PR is intentionally back to the original Ctrl+C-only patch. I also added the focused issue #14460, refreshed the description against the current template, and replaced the recordings with cropped, enlarged Before/After GIFs that show both Ctrl+C presses and the final terminal state.

@nwparker

Copy link
Copy Markdown
Contributor

Your diagnosis was right and I built on it — thank you for the measured event shape and the recordings, they made this quick to confirm.

I landed a widened fix in #14462 (e2e7768), which supersedes this. Two things came out of it that are worth your time:

1. It is not Korean-only. Any non-Latin source hits it — Russian and Greek fail identically, since key carries the layout's own glyph.

2. A measurement that I think breaks the layout-map approach. I probed every installed layout on a real macOS host with UCKeyTranslate at virtual keycode 8 (physical C):

com.apple.keylayout.ABC          -> c  U+0063
com.apple.keylayout.2SetHangul   -> ㅊ U+314A
com.apple.keylayout.Russian      -> с  U+0441

Korean 2-Set is a keyboard layout, not an IME layered over QWERTY — its KeyC really is ㅊ at the OS level. So getLayoutBaseCharacterForCode("KeyC") returns ㅊ, and normalizedKey === "c" stays false. The bug would survive. Your unit test passes because it stubs the map with [["KeyC", "c"]], which is the one assumption the hardware contradicts.

Caveat I want to be honest about: I measured the OS layout, not Chromium's navigator.keyboard.getLayoutMap(). If Chromium substitutes an ASCII-capable layout for non-Latin sources, your patch works and my tier 2 fires instead of tier 3. I could not measure Chromium's answer under a live Korean source. Given your before/after recordings show it working, it is possible Chromium does exactly that — if you injected the synthetic event shape rather than typing on a live source, that would explain both observations.

The merged fix keeps your layout-map idea as tier 2 (it is what makes a genuine IME-over-Latin source precise rather than merely positional) and adds a positional fallback as tier 3 for true non-Latin layouts. So it lands the same answer either way.

Closing thought: if you can measure navigator.keyboard.getLayoutMap().get("KeyC") with 2-Set actually active, I would genuinely like to know the result — it decides which tier is doing the work, and I could not get that one myself.

#13331 (Ctrl+A / Ctrl+U) may be the same helper and worth re-testing on your side now.

@nwparker

Copy link
Copy Markdown
Contributor

Correction to my last line: I checked, and #13331 is not fixed by this. isTerminalInterruptCKey is Ctrl+C-only — Ctrl+A and Ctrl+U never reach it and go through xterm's own encoder on a separate path. Same root cause (a non-Latin key), different code, still open. Sorry, I should have verified before saying it.

@nwparker

Copy link
Copy Markdown
Contributor

Closing since #14462 landed and fixes #14460 — your diagnosis and your layout-map idea are both in it, credited in the PR body.

Not closing because the patch was wrong: it was a correct read of the bug and the first working analysis of it. It's superseded because the merged version widens it to every non-Latin source and adds the positional fallback the hardware measurement turned out to need.

Reopen if you disagree with the measurement — and if you can get navigator.keyboard.getLayoutMap().get("KeyC") under a live 2-Set source, I'd still like that number. #13331 is still open and is a separate code path, if you want the follow-up.

@nwparker nwparker closed this Aug 14, 2026
@hgijeon
hgijeon deleted the fix/terminal-ctrl-c-korean-ime branch August 14, 2026 07:50
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

2 participants