diff --git a/apps/web/src/components/settings/KeybindingsSettings.logic.test.ts b/apps/web/src/components/settings/KeybindingsSettings.logic.test.ts index 0a4735861c0ad..4468d0ee66a14 100644 --- a/apps/web/src/components/settings/KeybindingsSettings.logic.test.ts +++ b/apps/web/src/components/settings/KeybindingsSettings.logic.test.ts @@ -186,6 +186,31 @@ describe("KeybindingsSettings.logic", () => { expected: "alt+1", defaultInput: "alt+1", }, + { + key: "π", + code: "KeyP", + altKey: true, + shiftKey: false, + expected: "alt+p", + defaultInput: "alt+p", + }, + // Dvorak Option+L and AZERTY Option+A: not the US glyph at its US key. + { + key: "¬", + code: "KeyP", + altKey: true, + shiftKey: false, + expected: "alt+¬", + defaultInput: "alt+¬", + }, + { + key: "æ", + code: "KeyQ", + altKey: true, + shiftKey: false, + expected: "alt+æ", + defaultInput: "alt+æ", + }, ]) { const pressed = { key, diff --git a/packages/shared/src/keybindingMatching.ts b/packages/shared/src/keybindingMatching.ts index e6525b53d8777..75e6786cd1429 100644 --- a/packages/shared/src/keybindingMatching.ts +++ b/packages/shared/src/keybindingMatching.ts @@ -46,6 +46,32 @@ export const EVENT_CODE_SHORTCUT_KEYS: Readonly> = { Slash: "/", }; +// macOS US layout Option+letter glyphs (Option+P types "π"). Dead keys (E, I, N, U) are absent. +const US_MAC_OPTION_GLYPH_LETTERS: ReadonlyMap = new Map([ + ["å", "a"], + ["∫", "b"], + ["ç", "c"], + ["∂", "d"], + ["ƒ", "f"], + ["©", "g"], + ["˙", "h"], + ["∆", "j"], + ["˚", "k"], + ["¬", "l"], + ["µ", "m"], + ["ø", "o"], + ["π", "p"], + ["œ", "q"], + ["®", "r"], + ["ß", "s"], + ["†", "t"], + ["√", "v"], + ["∑", "w"], + ["≈", "x"], + ["¥", "y"], + ["Ω", "z"], +]); + export function isMacPlatform(platform: string): boolean { return /mac|iphone|ipad|ipod/i.test(platform); } @@ -61,6 +87,9 @@ export function shortcutKeyFromEvent( ): string { const layoutKey = normalizeEventKey(event.key); if (/^[a-z]$/.test(layoutKey)) return layoutKey; + // Only the US layout's glyph at its own key: other layouts and AltGr keep their character. + const usOptionLetter = event.altKey ? US_MAC_OPTION_GLYPH_LETTERS.get(event.key) : undefined; + if (usOptionLetter && event.code === `Key${usOptionLetter.toUpperCase()}`) return usOptionLetter; // An unshifted "+" is a dedicated zoom key (German, Spanish, Nordic); Czech types it on Digit1. const isZoomPlus = layoutKey === "+" && !event.shiftKey && !event.altKey; if (isZoomPlus && !event.code?.startsWith("Digit")) return layoutKey;