Fix keyboard shortcuts not working with Korean (한글) input mode

When a non-Latin input source like Korean 두벌식 is active,
event.charactersIgnoringModifiers returns Hangul characters (e.g. ㅅ
for T key) instead of Latin letters. This caused all character-based
shortcut matching to fail — Cmd+T, Cmd+D, Cmd+1-9, Ctrl+N/P, etc.

Root cause: KeyboardLayout.character(forKeyCode:modifierFlags:) assumed
CJK input sources lack kTISPropertyUnicodeKeyLayoutData, but Korean
두벌식 has it. UCKeyTranslate returned Korean characters and the ASCII
fallback was never reached.

Fix:
- KeyboardLayout.character(): check result is ASCII before accepting;
  fall through to TISCopyCurrentASCIICapableKeyboardInputSource() when
  the current source returns non-ASCII characters
- Add KeyboardLayout.normalizedCharacters(for:) helper that normalizes
  event.charactersIgnoringModifiers for shortcut comparison
- Apply normalization in handleCustomShortcut (AppDelegate),
  BrowserPanelView omnibar key handler, and BrowserPopupWindowController
  Cmd+W handler

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
최준영 2026-03-21 21:16:10 +09:00
parent 6ff81579d9
commit 8cd9cd96c1
4 changed files with 31 additions and 8 deletions

View file

@ -8889,7 +8889,11 @@ final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCent
private func handleCustomShortcut(event: NSEvent) -> Bool {
// `charactersIgnoringModifiers` can be nil for some synthetic NSEvents and certain special keys.
// Treat nil as "" and rely on keyCode/layout-aware fallback logic where needed.
let chars = (event.charactersIgnoringModifiers ?? "").lowercased()
// When a non-Latin input source is active (Korean, Chinese, Japanese, etc.),
// charactersIgnoringModifiers returns non-ASCII characters that never match
// Latin shortcut keys. Normalize via KeyboardLayout so downstream comparisons
// (Cmd+1-9, Ctrl+1-9, omnibar N/P, command palette, etc.) work correctly.
let chars = KeyboardLayout.normalizedCharacters(for: event)
let flags = event.modifierFlags.intersection(.deviceIndependentFlagsMask)
let hasControl = flags.contains(.control)
let hasCommand = flags.contains(.command)