Skip to content

fix(terminal): honor key-binding remaps of the Korean ₩ key - #11177

Closed
jeongph wants to merge 1 commit into
stablyai:mainfrom
jeongph:fix/terminal-korean-won-key-remap
Closed

jeongph wants to merge 1 commit into
stablyai:mainfrom
jeongph:fix/terminal-korean-won-key-remap

Conversation

@jeongph

@jeongph jeongph commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #11170.

macOS Korean input sources put ₩ (U+20A9) on the Backquote key, so a backtick is unreachable without switching input source. The standard workaround is a ~/Library/KeyBindings/DefaultKeyBinding.dict remap:

{ "₩" = ("insertText:", "`"); }

That remap works in every other app — including Orca's own text inputs — but not in the Orca terminal, which sends the raw ₩ to the PTY.

Why: AppKit applies the substitution in the text input path, and Chromium surfaces the result only on the keypress/input events. Probe capture with a Korean input source active:

keydown   key="₩" U+20A9  code=Backquote  keyCode=192  isComposing=false
keypress  key="₩" U+20A9  charCode=96          <- 96 = `
input     data="`" U+0060 inputType=insertText <- committed text

xterm derives the PTY payload from keydown.key and calls preventDefault(), which makes Chromium suppress the following Char event — so the keypress and input carrying ` never fire and only the raw layout character survives.

₩ fell through all three existing guards: CJK_DIRECT_PUNCTUATION_KEYS carries ¥ (U+FFE5) but not ₩ (U+20A9); the non-ASCII bypass in xterm-bypass-policy.ts is scoped to event.shiftKey; and terminal-jis-yen-input.ts is scoped to code === 'IntlYen' behind an opt-in setting.

Change: add ₩ to CJK_DIRECT_PUNCTUATION_KEYS so installTerminalImeNativeTextForwarder claims the keydown, routes it around xterm, and forwards the committed glyph from the input event — the mechanism this file already provides for "committed text differs from keydown.key". Users without the dict are unaffected: the forwarder passes through whatever text actually commits, which is ₩.

Considered and rejected: dropping the shiftKey condition from the non-ASCII bypass. It would cover any dict-remapped non-ASCII key, but it changes the code path for every keystroke on all non-Latin layouts (Cyrillic, Greek, Thai, …) and silently drops keys that emit no keypress. Too broad for this defect.

Screenshots

No visual change.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test
  • pnpm build
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

Three regression tests in terminal-ime-native-text-forwarder.test.ts, written failing first and confirmed failing before the fix:

  1. ₩ keydown is a native-text candidate even when the input-source probe is stale.
  2. The dict substitution (`) is forwarded from the input event.
  3. ₩ is forwarded unchanged when no dict remap exists — pins the behavior for users who do not remap.

terminal-pane suite: 193 files / 2522 tests pass. Full suite: 8 files / 43 tests fail, all pre-existing — verified identical failure counts on upstream/main without this change (window.localStorage is not implemented under Node 25.x, plus one flaky timing assertion). oxlint findings on this machine came only from untracked local worktree copies under .orca/ and .claude/; scoped to src config tests mobile it is clean.

AI Review Report

Reviewed with systematic root-cause debugging rather than symptom patching: captured real key-event evidence before proposing a fix, confirmed the xterm payload rule in the shipped bundle (keyCode >= 48 && key.length === 1 → result.key = ev.key), and verified _keyPress reads e.charCode and stays reachable because _keyDownHandled remains false when a custom handler bypasses the keydown.

Risks checked:

  • Blast radius. isImeNativeTextKeydownCandidate has exactly one consumer, terminal-ime-native-text-forwarder.ts, which use-terminal-pane-lifecycle.ts installs only when isMac; on Windows and Linux claimKeyEvent is a constant false, so this is a no-op there. No shortcut, accelerator, label, or path handling is touched, and nothing here assumes local execution, so SSH sessions and folder workspaces behave identically.
  • Regression for non-remapping users. Covered by test 3 above: the forwarder sends the actual committed text, so an unremapped ₩ still arrives as ₩.
  • Modifier chords. Unchanged — isImeNativeTextKeydownCandidate still rejects Ctrl/Alt/Meta, so Option+₩ continues to fall through to terminalMacOptionAsAlt as before.
  • Composition safety. Unchanged — composing keystrokes and active compositions are still rejected before the candidate check, so Hangul composition is untouched.
  • Dropped input. If no input event followed a claimed keydown the glyph would be lost; the existing 100 ms disarm timer and keyup handling already cover that, and the probe shows the input event always fires for this key.

Security Audit

No new IPC, command execution, path handling, auth, secrets, or dependency surface. The only data flow added is an existing one widened by one character: text from a focused terminal element's InputEvent.data is passed to pane.terminal.input() — the same path every typed character already takes, subject to the same PTY input guards. Input is a single committed glyph from the OS text input system, not attacker-controlled content, and it is neither parsed nor interpolated into a command. No follow-up needed.

Notes

  • macOS-only in effect, though the constant is platform-neutral.
  • Reproduces only while a Korean input source is active; with ABC selected keydown.key is already `.
  • Likely affects any xterm.js-based terminal, so this is less an Orca-specific defect than a gap in guards Orca already ships.
  • Out of scope: the companion "~₩" = ("insertText:", "₩") dict rule (Option + the key). Modifier chords are deliberately excluded from the native-text claim, and terminalMacOptionAsAlt consumes Option first. Left unchanged rather than widening the claim to modifier chords.

macOS Korean input sources put ₩ (U+20A9) on Backquote, so users remap it
to ` via ~/Library/KeyBindings/DefaultKeyBinding.dict. AppKit applies that
substitution in the text input path, and Chromium surfaces it only on the
keypress/input events — keydown still carries the raw ₩. xterm derives the
PTY payload from keydown.key and preventDefault()s, which suppresses the
Char event, so the remapped ` never reaches the shell.

₩ fell through every existing guard: CJK_DIRECT_PUNCTUATION_KEYS has ¥
(U+FFE5) but not ₩, the non-ASCII xterm bypass is scoped to shifted keys,
and the JIS Yen rewrite is scoped to code === 'IntlYen'. Claiming it as a
native-text candidate routes the keydown around xterm so the committed
glyph is forwarded from the input event.

Fixes stablyai#11170
@coderabbitai

coderabbitai Bot commented Jul 28, 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: eff489d3-d28f-4ca6-84f2-2b48ec148220

📥 Commits

Reviewing files that changed from the base of the PR and between 0404f27 and 2cb6a50.

📒 Files selected for processing (2)
  • src/renderer/src/components/terminal-pane/terminal-ime-native-text-candidates.ts
  • src/renderer/src/components/terminal-pane/terminal-ime-native-text-forwarder.test.ts

📝 Walkthrough

Walkthrough

Adds the Korean won symbol (₩) to direct punctuation key candidates, including stale input-source handling for Backquote-shaped key events. Tests verify that the IME forwarder sends a remapped backtick when key binding substitution applies and forwards ₩ unchanged when no remapping applies.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: honoring Korean ₩ key-binding remaps in the terminal.
Description check ✅ Passed The description includes all required sections and the testing, AI review, security, and notes details are sufficiently filled out.
Linked Issues check ✅ Passed The code and tests address #11170 by claiming ₩ as native text, forwarding the committed backtick, and preserving the no-remap path.
Out of Scope Changes check ✅ Passed The changes stay within the reported fix and its regression tests, with no unrelated code paths or features introduced.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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.

@jeongph

jeongph commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

Heads up: this PR now has no remaining delta against main.

Rebasing fix/terminal-korean-won-key-remap onto main drops the commit entirely — the branch becomes identical to main. Both halves already landed through #11293 (fix(terminal): reconcile cross-platform IME composition lifecycle, merged 2026-07-29):

  • terminal-ime-native-text-candidates.ts carries '₩' in CJK_DIRECT_PUNCTUATION_KEYS`, with the same comment.
  • terminal-ime-native-text-forwarder.test.ts carries both cases — accepts the Korean won-sign key even when the input source probe is stale and forwards the key binding substitution for the Korean won-sign key.

The CONFLICTING status is just the test file: #11293 added Korean-jamo cases immediately above the won-sign block, and resolving that conflict leaves nothing behind.

Leaving this open for a maintainer to call — closing as superseded by #11293 looks right to me, but I would rather not close it myself in case any part of the fix is still wanted separately.

@jeongph

jeongph commented Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

Closing as superseded — confirmed against main at 9a81874.

The '₩' entry landed via #11293, and the file this PR edits (terminal-ime-native-text-candidates.ts) has since been deleted outright by #13128 (refactor(terminal): return IME composition ownership to xterm) and #13288. Rebasing now yields a modify/delete conflict with nothing left to apply.

Coverage for the remap case lives on in terminal-ime-won-composition-order.test.ts, which asserts composition-first ordering when the won key commits as either \`` or ₩`, plus an immediate won remap after repeated stale composition ends. Nothing to carry forward.

@jeongph jeongph closed this Aug 13, 2026
@jeongph
jeongph deleted the fix/terminal-korean-won-key-remap branch October 17, 2026 13:13
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]: Terminal ignores DefaultKeyBinding.dict remap of the Korean ₩ key

2 participants