Skip to content

feat(terminal): Korean Won (₩) → backquote key mapping for Korean keyboards - #13104

Merged
nwparker merged 2 commits into
stablyai:mainfrom
hyein-cbio:hyein-cbio/quahog
Aug 8, 2026
Merged

nwparker merged 2 commits into
stablyai:mainfrom
hyein-cbio:hyein-cbio/quahog

Conversation

@hyein-cbio

@hyein-cbio hyein-cbio commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Korean keyboard layouts put a different character on the key that US layouts reserve for the backquote (`):

  • 두벌식 (2-set) and 세벌식 390: ₩
  • 세벌식 최종: *

So Korean terminal users cannot type a backquote — markdown code fences and shell backquotes require switching layouts or copy-paste. This adds a Mac-only terminal setting, "Korean Won (₩) to Backquote (`)" (Terminal → Advanced, right below the existing JIS Yen mapping), that rewrites the plain backquote-position keystroke to backquote while a Korean input source is active.

Stronger framing from the IME work (#12560): native terminals don't need this setting because they honour a user's own DefaultKeyBinding.dict remap of ₩; Orca's terminal ignores it (#11170). This PR compensates for a defect we own, which is a stronger justification than parity with the JIS Yen setting.

Screenshots

A new settings toggle row appears in Settings → Terminal → Advanced. No other visual change; the toggle looks identical to the JIS Yen row above it.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test (resolver + settings + i18n suites; full renderer suites green)
  • pnpm build
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

Unit tests cover the rewrite resolver (position-based rule, modifier exclusion, IME keyCode 229 guard, all gates), the settings search index, and the i18n catalog. Manual GUI verification on macOS with 한국어 - 두벌식 input source, including Caps Lock / 한영 switching.

AI Review Report

CodeRabbit review (CLI, --base-commit HEAD) flagged 4 findings in the first input-source module — all resolved by deleting that module and reusing the existing MacNativeTextInputSourceTracker (which already refreshes on focus and keyboard activity). A follow-up PR review found no findings. One Minor copy finding (setting precondition not stated) is fixed in this revision.

Cross-platform check: the feature is Mac-only by design (UI gated on isMac, mirroring JIS Yen; the input-source IPC returns null off-Darwin). Windows/Linux behavior is untouched — the rewrite cannot fire because the gate requires macOS + a Korean input source. No shortcuts, labels, paths, or shell behavior change on any platform; the rewrite injects via xterm's existing onData path so PTY input guards still run.

Security Audit

No new input handling beyond a keydown rewrite that already exists for JIS Yen; no command execution, path handling, auth, secrets, or dependency changes. The only IPC touched is the pre-existing read-only app:getKeyboardInputSourceId (HIToolbox prefs read). No follow-up needed.

Notes

@coderabbitai

coderabbitai Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds the terminalKoreanWonToBackquote setting with a default value of false. Adds a macOS settings control and localized search metadata. Adds Korean input-source detection and caching. Adds Korean Won key event resolution for Korean keyboards, including IME and modifier filtering. Integrates resolved input into the terminal lifecycle and adds tests for configuration, platform, keyboard layout, input-source, and event behavior.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 35.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main feature: mapping the Korean Won key to backquote for terminal use.
Description check ✅ Passed The description covers the change, testing, review, security, cross-platform behavior, trade-offs, and merge-order notes; the build remains unchecked.
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.

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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ebbc445f-a684-4430-ad6c-2fb08c9f5670

📥 Commits

Reviewing files that changed from the base of the PR and between 38275c2 and eda76a740fe032890719768021141827e8ce3001.

📒 Files selected for processing (12)
  • src/main/codex-accounts/runtime-home-service.test.ts
  • src/main/codex-accounts/service.test.ts
  • src/renderer/src/components/settings/TerminalMacKeyboardSection.tsx
  • src/renderer/src/components/settings/terminal-advanced-platform-search.ts
  • src/renderer/src/components/settings/terminal-search.test.ts
  • src/renderer/src/components/settings/terminal-search.ts
  • src/renderer/src/components/terminal-pane/terminal-korean-won-input.test.ts
  • src/renderer/src/components/terminal-pane/terminal-korean-won-input.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts
  • src/renderer/src/i18n/locales/en.json
  • src/shared/constants.ts
  • src/shared/types.ts

@AmethystLiang
AmethystLiang requested review from nwparker and removed request for brennanb2025 August 8, 2026 01:51
@nwparker

nwparker commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Thanks! I'm working on a larger IME change but I let me look into this one and ensure it gets resolved!
Will get those changes out today, I think

@nwparker

nwparker commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Heads-up on a merge-order conflict, from the IME remediation branch (#12560) — plus a note that I think this PR is worth landing.

The conflict. #12560 removes the first-party terminal IME layer entirely (first-party terminal-IME source files go to zero; composition moves back to a patched xterm). Two things this PR depends on are deleted there:

  • src/renderer/src/components/terminal-pane/terminal-ime-input-source.ts — deleted
  • forwardHangulJamo — zero occurrences at that branch's HEAD

Both PRs also modify use-terminal-pane-lifecycle.ts (#12560 removes ~122 lines from it).

#12560 is expected to merge first, so the live input-source gate here will need rebasing onto whatever replaces it. Flagging early so it isn't a surprise at merge time — the feature itself is unaffected, only the mechanism it queries.

On the merits, from the IME work: this is measured, not speculative. Sealed hardware evidence on macOS shows the grave key emitting e2 82 a9 (₩) under a Korean input source, against 60 (`) under ABC on the same key and same build. So Korean users genuinely cannot type a backquote.

Worth adding to the motivation: native terminals don't need this setting because they honour a user's own DefaultKeyBinding.dict remap of ₩. Orca's terminal ignores it — that's #11170, where the decisive control was the same key in an ordinary Chromium <input> honouring the dict while the terminal dropped it. So this PR is compensating for a defect we own, which is a stronger justification than parity with the JIS Yen setting.

One consequence worth stating explicitly in the PR: with this on, ₩ becomes untypable in the terminal. That seems right for a currency symbol versus a shell metacharacter, but it should be a documented trade rather than a surprise.

Two small things from adjacent work that may be useful here:

  1. Gate on event.code, not event.key. A CJK input source rewrites key while code keeps the physical key — that confusion owned [Bug]: In 1.4.164 version, Korean typing is reflected very late in Terminal #12171 (a Shift+T typing ㅆ read as Enter) and [Bug]: Cmd+C jumps terminal scrollback to the bottom with Korean input on macOS #13033 (Cmd+C arriving as { key: "ㅊ", code: "KeyC" }). refactor(terminal): remove the IME composition handler, with recorded-trace regression tests #12560 adds @/lib/ime-latin-shortcut-key for exactly this.
  2. keyCode === 229 means an IME owns the press. The existing terminal-jis-yen-input.ts already excludes it, and the same guard applies here.

@hyein-cbio

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review! Quick alignment notes on the two implementation points:

  1. Gate on event.code, not event.key — already the case. The resolver dropped the key === '₩' check entirely and keys only on code === 'Backquote' (the physical key), so CJK key rewriting can't confuse it (cf. [Bug]: In 1.4.164 version, Korean typing is reflected very late in Terminal #12171/[Bug]: Cmd+C jumps terminal scrollback to the bottom with Korean input on macOS #13033).
  2. keyCode === 229 guard — present, mirroring terminal-jis-yen-input.ts; IME-owned presses pass through untouched.

Also addressed in the PR description:

The settings copy was also updated to state the Korean-input-source precondition (per the CodeRabbit Minor finding). Thanks for shepherding this one!

Korean keyboard users type markdown code fences and shell backquotes on the key that US layouts reserve for ` — 두벌식 and 세벌식 390 put ₩ there, 세벌식 최종 puts *, so there was no way to type a backquote without switching layouts.

Add a Mac-only terminal setting, "Korean Won (₩) to Backquote (`)", that rewrites the plain backquote-position keystroke to backquote while a Korean input source is active. It sits in Terminal → Advanced, right below the existing JIS Yen (¥) to Backslash (\) mapping.

The rewrite keys on the keystroke position alone — no character or layout-variant knowledge — and follows the live input source through the existing MacNativeTextInputSourceTracker, which refreshes on focus and keyboard activity (Caps Lock / 한영 input switches never blur the window). Modified chords and IME-composed events pass through untouched.

Covered by resolver and input-source tracker unit tests; verified manually in the GUI.
State in the setting copy that the backquote rewrite applies only while a Korean input source is active, and add JSDoc to the Korean Won resolver exports (addresses CodeRabbit pre-merge docstring coverage and copy-clarity findings).
@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@hyein-cbio

Copy link
Copy Markdown
Contributor Author

Rebase complete — #12560 landed and this PR is now MERGEABLE against the new main.

What changed to survive the IME remediation:

  • terminal-ime-input-source.ts (and forwardHangulJamo) is gone, so the gate now reads the existing app:getKeyboardInputSourceId IPC directly via a small korean-input-source.ts module.
  • It keeps the real-time refresh property that mattered: focus-in plus keyboard activity (Caps Lock / 한영 input-toggle keys refresh immediately, other keys at most once per 2s cooldown), with a generation guard so stale probes can't overwrite fresher results.
  • The resolver itself is untouched — still gates on event.code === 'Backquote' (physical key, not key) and excludes keyCode 229 (IME-owned presses).

Verified: resolver + gate tests pass, typecheck and lint green. One pre-existing note: 5 IME/xterm composition test files fail on plain origin/main too (confirmed via a clean worktree) — unrelated to this PR.

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/renderer/src/lib/keyboard-layout/korean-input-source.ts (1)

1-25: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Reduce the module header comment.

Keep the physical-key rationale. Remove the layout inventory and macOS preference implementation details. Move long operational details to documentation if needed.

As per coding guidelines, comments must be concise, limited to non-obvious information, and preferably one line.

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3454e6c3-98ce-40c5-ab44-dc2ba39705cb

📥 Commits

Reviewing files that changed from the base of the PR and between c991bb2 and e658fac.

📒 Files selected for processing (15)
  • src/main/codex-accounts/runtime-home-service.test.ts
  • src/main/codex-accounts/service.test.ts
  • src/renderer/src/components/settings/TerminalMacKeyboardSection.tsx
  • src/renderer/src/components/settings/terminal-advanced-platform-search.ts
  • src/renderer/src/components/settings/terminal-search.test.ts
  • src/renderer/src/components/settings/terminal-search.ts
  • src/renderer/src/components/terminal-pane/keyboard-handlers.ts
  • src/renderer/src/components/terminal-pane/terminal-korean-won-input.test.ts
  • src/renderer/src/components/terminal-pane/terminal-korean-won-input.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/lib/keyboard-layout/korean-input-source.test.ts
  • src/renderer/src/lib/keyboard-layout/korean-input-source.ts
  • src/shared/constants.ts
  • src/shared/types.ts
🚧 Files skipped from review as they are similar to previous changes (12)
  • src/main/codex-accounts/service.test.ts
  • src/main/codex-accounts/runtime-home-service.test.ts
  • src/renderer/src/i18n/locales/en.json
  • src/shared/constants.ts
  • src/renderer/src/components/settings/terminal-search.test.ts
  • src/shared/types.ts
  • src/renderer/src/components/terminal-pane/terminal-korean-won-input.test.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts
  • src/renderer/src/components/settings/terminal-advanced-platform-search.ts
  • src/renderer/src/components/settings/TerminalMacKeyboardSection.tsx
  • src/renderer/src/components/settings/terminal-search.ts
  • src/renderer/src/components/terminal-pane/terminal-korean-won-input.ts

Comment on lines +79 to +85
try {
return await reader()
} catch {
// Why: the IPC can transiently reject during main-process teardown; treat
// as no signal so the rewrite stays off instead of guessing.
return null
}

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Preserve the cached classification when IPC fails.

This catch converts a rejected IPC request to null. Line 104 then clears a previously known Korean state. This bypasses the failure-preservation path in refreshInputSourceId and disables the mapping after a transient IPC failure.

Proposed fix
-    try {
-      return await reader()
-    } catch {
-      // Why: the IPC can transiently reject during main-process teardown; treat
-      // as no signal so the rewrite stays off instead of guessing.
-      return null
-    }
+    return reader()
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
try {
return await reader()
} catch {
// Why: the IPC can transiently reject during main-process teardown; treat
// as no signal so the rewrite stays off instead of guessing.
return null
}
return reader()

@nwparker

nwparker commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Following up on my earlier heads-up about the deleted composition layer — you got there first. I can confirm this is fully rebased: git merge-base origin/main <head> equals main's tip c991bb27d34 exactly, and git grep for forwardHangulJamo, terminal-ime-input-source and macNativeTextInputSourceTracker returns zero hits on the branch. Nothing left blocking from our side.

I also confirmed this is not made redundant by 17b3dff. That commit changed composition ownership, not what the Korean layout maps onto the physical key. There is no ₩→backquote rewrite anywhere on main, and main's xterm-bypass-policy.test.ts:125-133 positively asserts that {key:'₩', code:'Backquote', keyCode:192} is bypassed to macOS native text input on both keydown and keyup — so main deliberately types ₩ verbatim. The defect this fixes still reproduces there.

Gates are green on the head with config/*.tsbuildinfo cleared first (that staleness has produced false greens for us before): tsc node+cli+web, oxlint type-aware with --deny-warnings, oxfmt, and 4056 tests across terminal-pane/keyboard-layout/settings. Gating on event.code === 'Backquote' and putting keyCode !== 229 first in isPlainBackquoteKeystroke are both exactly right — reading key here is what bit us in #12171 and #13033.

Two non-blocking findings.

1. prefetchKoreanInputSource() is not gated on the setting — keyboard-handlers.ts:264-268 calls it under a bare if (isMac). The probe runs /usr/bin/defaults export com.apple.HIToolbox - | /usr/bin/plutil -extract … | /usr/bin/plutil -convert json …, so four processes in the main process, on a ≤1-per-2000ms-of-typing refresh — for every macOS user, while terminalKoreanWonToBackquote defaults to false (src/shared/constants.ts:349). Input-source toggle keys pass force: true, so a single Caps Lock press costs two probes regardless. Not a one-liner since keyboard-handlers.ts has no settings in scope; the tidiest fix is a lazy call from the lifecycle, where settingsRef.current?.terminalKoreanWonToBackquote is already read a line away.

2. One integration path is untested. Ordering is safe — the Korean block at use-terminal-pane-lifecycle.ts:924-935 runs before shouldBypassXtermKeyboardEvent at :955 and returns false, so the bypass is never reached. But main's bypass policy exists because ₩ on Backquote arrives via the macOS native text path, and nothing covers whether returning false actually suppresses that native insertion. If it doesn't, the user gets both ` and ₩. The terminalJISYenToBackslash sibling ships the identical pattern, which is reassuring but isn't proof. Worth one manual check on a real Korean input source before merge — synthetic events won't answer it.

Minor: defaultInputSourceIdReader() in korean-input-source.ts is a verbatim copy of the one in option-as-alt-probe.ts, comment included — worth extracting.

@nwparker
nwparker merged commit 2400393 into stablyai:main Aug 8, 2026
46 checks passed
@hyein-cbio
hyein-cbio deleted the hyein-cbio/quahog branch August 8, 2026 10:59
nwparker added a commit that referenced this pull request Aug 9, 2026
* Revert "fix(terminal): detach the Korean input-source probe when its setting goes off (#13283)"

This reverts commit 5a84dbb.

* Revert "fix(terminal): stop the Korean gate caching an unknown input source as negative (#13182)"

This reverts commit 4349599.

* Revert "perf(terminal): gate the Korean input-source probe on its setting (#13181)"

This reverts commit 42fc537.

* Revert "feat(terminal): Korean Won (₩) → backquote key mapping for Korean keyboards (#13104)"

This reverts commit 2400393.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…boards (stablyai#13104)

* feat(terminal): map Korean Won (₩) key to backquote on macOS

Korean keyboard users type markdown code fences and shell backquotes on the key that US layouts reserve for ` — 두벌식 and 세벌식 390 put ₩ there, 세벌식 최종 puts *, so there was no way to type a backquote without switching layouts.

Add a Mac-only terminal setting, "Korean Won (₩) to Backquote (`)", that rewrites the plain backquote-position keystroke to backquote while a Korean input source is active. It sits in Terminal → Advanced, right below the existing JIS Yen (¥) to Backslash (\) mapping.

The rewrite keys on the keystroke position alone — no character or layout-variant knowledge — and follows the live input source through the existing MacNativeTextInputSourceTracker, which refreshes on focus and keyboard activity (Caps Lock / 한영 input switches never blur the window). Modified chords and IME-composed events pass through untouched.

Covered by resolver and input-source tracker unit tests; verified manually in the GUI.

* docs(terminal): clarify Korean Won mapping scope and add docstrings

State in the setting copy that the backquote rewrite applies only while a Korean input source is active, and add JSDoc to the Korean Won resolver exports (addresses CodeRabbit pre-merge docstring coverage and copy-clarity findings).
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* Revert "fix(terminal): detach the Korean input-source probe when its setting goes off (stablyai#13283)"

This reverts commit 4b8d3e9.

* Revert "fix(terminal): stop the Korean gate caching an unknown input source as negative (stablyai#13182)"

This reverts commit d7061e0.

* Revert "perf(terminal): gate the Korean input-source probe on its setting (stablyai#13181)"

This reverts commit 0712e9a.

* Revert "feat(terminal): Korean Won (₩) → backquote key mapping for Korean keyboards (stablyai#13104)"

This reverts commit eee48f8.
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.

2 participants