Skip to content

fix(keyboard): support CJK input methods for custom shortcuts - #1770

Closed
pstanton237 wants to merge 1 commit into
manaflow-ai:mainfrom
pstanton237:fix/cjk-ime-shortcuts
Closed

pstanton237 wants to merge 1 commit into
manaflow-ai:mainfrom
pstanton237:fix/cjk-ime-shortcuts

Conversation

@pstanton237

@pstanton237 pstanton237 commented Mar 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Keyboard shortcuts handled through handleCustomShortcut (not registered as SwiftUI menu items) fail when a CJK input method (Korean, Japanese, Chinese) is active. For example, Cmd+T (New Terminal) and Cmd+Shift+L (Open Browser) do not work with Korean 2-Set IME, while menu-registered shortcuts like Cmd+B (Toggle Sidebar) and Cmd+D (Split Right) work fine because AppKit's menu system processes them before the IME.

Root cause: When a CJK IME is active, event.charactersIgnoringModifiers returns non-ASCII characters (e.g. "ㅅ" for the T key). Two gates in matchShortcut treat these non-ASCII characters as valid character data and block the ANSI keyCode fallback path:

  1. The strict character-match gate returns false early for letter-based Command shortcuts when characters are present but don't match
  2. The ANSI keyCode fallback condition requires both event characters and layout characters to be absent, but Korean characters are non-empty

Fix: Treat non-ASCII characters from CJK input methods as absent for shortcut matching purposes — they cannot match ASCII shortcut keys, so the function falls through to keyCode-based matching which correctly identifies the physical key.

Test plan

  • Manually verified: Cmd+T creates new terminal with Korean 2-Set IME active
  • Manually verified: Cmd+Shift+L opens browser with Korean 2-Set IME active
  • Manually verified: Both shortcuts still work with English input source
  • Manually verified: Menu-registered shortcuts (Cmd+B, Cmd+D) unaffected
  • Added unit tests simulating Korean IME events for Cmd+T and Cmd+Shift+L
  • CI: existing shortcut routing tests pass

Fixes #1545


Summary by cubic

Fixes custom keyboard shortcuts failing when a CJK IME is active by ignoring non-ASCII IME characters and falling back to ANSI keyCode matching. Restores shortcuts like Cmd+T and Cmd+Shift+L under Korean/Japanese/Chinese IMEs without affecting menu-registered shortcuts.

  • Bug Fixes
    • Only treat charactersIgnoringModifiers and layout characters as usable when they are ASCII; otherwise match by physical keyCode.
    • Added tests simulating Korean IME for Cmd+T and Cmd+Shift+L; existing shortcut routing tests continue to pass.

Written for commit d7acb86. Summary will update on new commits.

Summary by CodeRabbit

  • Bug Fixes

    • Improved Command-key shortcut handling with Asian input methods (Korean, Japanese, Chinese). Shortcuts now reliably trigger when using CJK input method editors, fixing cases where non-ASCII characters previously prevented keyboard shortcuts from functioning.
  • Tests

    • Added test coverage for Command-key shortcut behavior with Korean IME input.

When a CJK input method (Korean, Japanese, Chinese) is active,
`event.charactersIgnoringModifiers` returns non-ASCII characters
(e.g. "ㅅ" for the T key on Korean 2-Set). The strict character-match
gate in `matchShortcut` treated these as valid ASCII characters and
returned `false` before reaching keyCode-based fallback, causing
shortcuts like Cmd+T and Cmd+Shift+L to silently fail.

Add an ASCII check so the gate only blocks fallback when the event
characters are actually ASCII — when they are non-ASCII (CJK IME),
fall through to ANSI keyCode matching which correctly identifies the
physical key.

Shortcuts registered as SwiftUI menu items (Cmd+B, Cmd+D, etc.) were
unaffected because AppKit's menu system processes them before the IME.

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@vercel

vercel Bot commented Mar 18, 2026

Copy link
Copy Markdown

@pstanton237 is attempting to deploy a commit to the Manaflow Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Mar 18, 2026 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 38fef1e9-9bcf-4d22-a846-6a1a0a35256e

📥 Commits

Reviewing files that changed from the base of the PR and between 63e65a7 and d7acb86.

📒 Files selected for processing (2)
  • Sources/AppDelegate.swift
  • cmuxTests/AppDelegateShortcutRoutingTests.swift

📝 Walkthrough

Walkthrough

Modified keyboard shortcut handling in AppDelegate to properly support CJK input methods by introducing ASCII-specific character validation checks and adjusting keyCode-based fallback logic. Added tests to verify shortcuts function correctly when non-ASCII IME characters are provided.

Changes

Cohort / File(s) Summary
IME-aware Shortcut Handling
Sources/AppDelegate.swift
Added ASCII-specific guards (hasUsableEventChars, hasUsableLayoutChar) to differentiate between usable ASCII input and non-ASCII IME output. Updated keycode-based fallback logic to gate on these new checks instead of simple character presence. Includes clarifying comments on non-ASCII input handling from Korean, Japanese, and Chinese IMEs.
Keyboard Shortcut Routing Tests
cmuxTests/AppDelegateShortcutRoutingTests.swift
Extended test helper with optional charsIgnoringModifiers parameter. Added two new test cases (testCmdTMatchesNewSurfaceWithKoreanIMECharacters, testCmdShiftLMatchesOpenBrowserWithKoreanIMECharacters) to validate that shortcuts correctly match via keyCode fallback when IME provides non-ASCII characters.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 Hops through the IME, ASCII or not,
Shortcuts find their way to the right key spot,
Korean, Japanese, characters so grand,
keyCode fallback helps you understand,
Now shortcuts work in every land! ✨

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

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 and usage tips.

@pstanton237

Copy link
Copy Markdown
Contributor Author

Closing as duplicate of #1649 which addresses the same CJK IME shortcut issue with a similar approach.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

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.

Kanban shortcut only works in the input language it was registered in (Korean/English)

1 participant