mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
fix(frontend): ignore a key event with no key in the shortcut handler
This commit is contained in:
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))
|
||||
})
|
||||
|
||||
@@ -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('+')
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user