Repository navigation
macos: translate physical menu shortcuts - #13888
Conversation
Translate printable physical keybindings through the current macOS keyboard layout before assigning menu key equivalents. Previously these bindings could not be represented because SwiftUI shortcuts are character-based, so actions such as super+backquote had no native menu shortcut. Keep native keycodes as dispatch identity so translated display characters do not change physical semantics or precedence over Unicode bindings. Refresh shortcuts when the input source changes, and prevent AppKit from transforming equivalents that are already localized.
Separate menu shortcut presentation from lookup identity. Store either a normalized key equivalent or a physical keycode in a private hashable enum, allowing Swift to synthesize equality and hashing instead of maintaining parallel optional-key logic. Assign display characters directly from KeyboardShortcut and remove unused NSMenuItem and SwiftUI conversion helpers.
Text Input Sources APIs are not thread-safe, but shortcut translation could be called outside a declared main-actor context. Mark keyboard layout and shortcut conversion as main-actor isolated, update their tests, and dispatch key-sequence UI notifications to the main queue before translating their shortcuts.
There was a problem hiding this comment.
I believe this also relates to #13180 and then #13205. But as I said in the comments there in #13180, core already use UCKeyTranslate. I wonder if there's a way to avoid this kinda duplication.
The changes looks good to me, but I haven't run it locally and want a second opinion on this.
Translate synthetic physical-key events with characters(byApplyingModifiers:). This preserves current-layout and Command-table behavior while avoiding a duplicate direct UCKeyTranslate implementation in Swift.
That's good feedback. I remember seeing #13180 go by but should have revisited it more closely. I revised this to use AppKit’s |
Yeah, true |
Translate printable physical keybindings through the current macOS keyboard layout before assigning menu key equivalents. Previously these bindings could not be represented because SwiftUI shortcuts are character-based, so actions such as
super+backquotehad no native menu shortcut.Keep native keycodes as dispatch identity so translated display characters do not change physical semantics or precedence over Unicode bindings. Refresh shortcuts when the input source changes, and prevent AppKit from transforming equivalents that are already localized.
AI Usage: The approach was suggested by GPT 5.6 Sol, but I wrote most of the code and understand it all.