From c87df9de4b5a1376a8efbab06a08ea6c8e14eb03 Mon Sep 17 00:00:00 2001 From: Chris Scott <99081550+chriswritescode-dev@users.noreply.github.com> Date: Fri, 6 Nov 2026 08:41:43 -0500 Subject: [PATCH] fix(frontend): ignore a key event with no key in the shortcut handler --- frontend/src/lib/keyboardShortcuts.test.ts | 7 +++++++ frontend/src/lib/keyboardShortcuts.ts | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/frontend/src/lib/keyboardShortcuts.test.ts b/frontend/src/lib/keyboardShortcuts.test.ts index 9e1dfce7..65d33622 100644 --- a/frontend/src/lib/keyboardShortcuts.test.ts +++ b/frontend/src/lib/keyboardShortcuts.test.ts @@ -23,6 +23,13 @@ describe('keyboardShortcuts', () => { expect(formatShortcutEvent(new KeyboardEvent('keydown', { key: 'Shift', shiftKey: true }))).toBeNull() }) + it('ignores a key event without a key, such as one Chrome autofill dispatches', () => { + const autofillEvent = new KeyboardEvent('keydown') + Object.defineProperty(autofillEvent, 'key', { value: undefined }) + + expect(formatShortcutEvent(autofillEvent)).toBeNull() + }) + it('returns the shared defaults with the key set', () => { expect(Object.keys(getDefaultKeyboardShortcuts())).toEqual(Object.keys(DEFAULT_KEYBOARD_SHORTCUTS)) }) diff --git a/frontend/src/lib/keyboardShortcuts.ts b/frontend/src/lib/keyboardShortcuts.ts index 418eca7b..52bf4c01 100644 --- a/frontend/src/lib/keyboardShortcuts.ts +++ b/frontend/src/lib/keyboardShortcuts.ts @@ -59,7 +59,7 @@ export function formatEventModifiers(e: KeyboardEvent): string { * Formats a keydown event as a canonical shortcut string such as `Cmd+Shift+Z`, or null for a lone modifier key. */ export function formatShortcutEvent(e: KeyboardEvent): string | null { - if (isModifierOnlyEvent(e)) return null + if (!e.key || isModifierOnlyEvent(e)) return null return [...eventModifiers(e), eventMainKey(e)].join('+') }