Skip to content

Commit 4849a95

Browse files
authored
Merge pull request #34 from github/fix-hotkey-selector
Fix invalid selector in hotkey query
2 parents a561e30 + a20936d commit 4849a95

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,18 @@ function focusKeydown(event: KeyboardEvent) {
363363

364364
const shortcutListeners = new WeakMap()
365365

366+
function findHotkey(toolbar: Element, key: string): HTMLElement | null {
367+
for (const el of toolbar.querySelectorAll<HTMLElement>('[hotkey]')) {
368+
if (el.getAttribute('hotkey') === key) {
369+
return el
370+
}
371+
}
372+
return null
373+
}
374+
366375
function shortcut(toolbar: Element, event: KeyboardEvent) {
367376
if ((event.metaKey && modifierKey === 'Meta') || (event.ctrlKey && modifierKey === 'Control')) {
368-
const button = toolbar.querySelector<HTMLElement>(`[hotkey="${event.key}"]`)
377+
const button = findHotkey(toolbar, event.key)
369378
if (button) {
370379
button.click()
371380
event.preventDefault()

0 commit comments

Comments
 (0)