fix(frontend): ignore a key event with no key in the shortcut handler

This commit is contained in:
Chris Scott committed 2026-11-06 08:41:43 -05:00
1 parent dc0220843e
commit c87df9de4b
2 files changed
+8 -1

No files matched your search

@@ -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))
})
+1 -1
View File
@@ -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('+')
}