From 644cc27fa709cd0334433fc425a5621ef09aee69 Mon Sep 17 00:00:00 2001 From: chloelee767 Date: Mon, 12 Jan 2026 23:05:42 +0800 Subject: [PATCH 1/2] fix alt shortcuts on mac not triggering --- apps/client/src/services/shortcuts.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/client/src/services/shortcuts.ts b/apps/client/src/services/shortcuts.ts index 167dc01d9..63db45302 100644 --- a/apps/client/src/services/shortcuts.ts +++ b/apps/client/src/services/shortcuts.ts @@ -213,8 +213,11 @@ export function keyMatches(e: KeyboardEvent, key: string): boolean { } // For letter keys, use the physical key code for consistency + // On macOS, Option/Alt key produces special characters, so we must use e.code if (key.length === 1 && key >= 'a' && key <= 'z') { - return e.key.toLowerCase() === key.toLowerCase(); + // e.code is like "KeyA", "KeyB", etc. + const expectedCode = `Key${key.toUpperCase()}`; + return e.code === expectedCode || e.key.toLowerCase() === key.toLowerCase(); } // For regular keys, check both key and code as fallback From a5e8c8f573f8b46cabef668e9d8a4157a451c573 Mon Sep 17 00:00:00 2001 From: chloelee767 Date: Tue, 13 Jan 2026 00:05:07 +0800 Subject: [PATCH 2/2] add tests --- apps/client/src/services/shortcuts.spec.ts | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/apps/client/src/services/shortcuts.spec.ts b/apps/client/src/services/shortcuts.spec.ts index b9576025f..6950c604c 100644 --- a/apps/client/src/services/shortcuts.spec.ts +++ b/apps/client/src/services/shortcuts.spec.ts @@ -100,6 +100,20 @@ describe("shortcuts", () => { expect(consoleSpy).toHaveBeenCalled(); consoleSpy.mockRestore(); }); + + it("should match letter keys using code when key is a special character (macOS Alt behavior)", () => { + // On macOS, pressing Option/Alt + A produces 'å' as the key, but code is still 'KeyA' + const macOSAltAEvent = createKeyboardEvent("å", "KeyA"); + expect(keyMatches(macOSAltAEvent, "a")).toBe(true); + + // Option + H produces '˙' + const macOSAltHEvent = createKeyboardEvent("˙", "KeyH"); + expect(keyMatches(macOSAltHEvent, "h")).toBe(true); + + // Option + S produces 'ß' + const macOSAltSEvent = createKeyboardEvent("ß", "KeyS"); + expect(keyMatches(macOSAltSEvent, "s")).toBe(true); + }); }); describe("matchesShortcut", () => { @@ -200,6 +214,33 @@ describe("shortcuts", () => { expect(consoleSpy).toHaveBeenCalled(); consoleSpy.mockRestore(); }); + + it("should match Alt+letter shortcuts on macOS where key is a special character", () => { + // On macOS, pressing Option/Alt + A produces 'å' but code remains 'KeyA' + const macOSAltAEvent = createKeyboardEvent({ + key: "å", + code: "KeyA", + altKey: true + }); + expect(matchesShortcut(macOSAltAEvent, "alt+a")).toBe(true); + + // Option/Alt + H produces '˙' + const macOSAltHEvent = createKeyboardEvent({ + key: "˙", + code: "KeyH", + altKey: true + }); + expect(matchesShortcut(macOSAltHEvent, "alt+h")).toBe(true); + + // Combined with Ctrl: Ctrl+Alt+S where Alt produces 'ß' + const macOSCtrlAltSEvent = createKeyboardEvent({ + key: "ß", + code: "KeyS", + ctrlKey: true, + altKey: true + }); + expect(matchesShortcut(macOSCtrlAltSEvent, "ctrl+alt+s")).toBe(true); + }); }); describe("bindGlobalShortcut", () => {