diff --git a/src/Common/Hooks/UseRegisterShortcut/UseRegisterShortcutProvider.tsx b/src/Common/Hooks/UseRegisterShortcut/UseRegisterShortcutProvider.tsx index e08d45236..71e0f5ede 100644 --- a/src/Common/Hooks/UseRegisterShortcut/UseRegisterShortcutProvider.tsx +++ b/src/Common/Hooks/UseRegisterShortcut/UseRegisterShortcutProvider.tsx @@ -31,7 +31,7 @@ const UseRegisterShortcutProvider = ({ }: UseRegisterShortcutProviderType) => { const disableShortcutsRef = useRef(false) const shortcutsRef = useRef>({}) - const keysDownRef = useRef>(new Set()) + const keysDownRef = useRef>>(new Set()) const keyDownTimeoutRef = useRef>(-1) const ignoredTags = ignoreTags ?? IGNORE_TAGS_FALLBACK @@ -116,38 +116,37 @@ const UseRegisterShortcutProvider = ({ }, []) const handleKeydownEvent = useCallback((event: KeyboardEvent) => { - if (keyDownTimeoutRef.current === -1) { - keyDownTimeoutRef.current = setTimeout(() => { - handleKeyupEvent() - }, shortcutTimeout ?? DEFAULT_TIMEOUT) - } - if (preventDefault) { event.preventDefault() } if ( ignoredTags.map((tag) => tag.toUpperCase()).indexOf((event.target as HTMLElement).tagName.toUpperCase()) > - -1 + -1 || + disableShortcutsRef.current ) { return } - if (!disableShortcutsRef.current) { - keysDownRef.current.add(event.key.toUpperCase()) + keysDownRef.current.add(event.key.toUpperCase() as Uppercase) - if (event.ctrlKey) { - keysDownRef.current.add('CONTROL') - } - if (event.metaKey) { - keysDownRef.current.add('META') - } - if (event.altKey) { - keysDownRef.current.add('ALT') - } - if (event.shiftKey) { - keysDownRef.current.add('SHIFT') - } + if (event.ctrlKey) { + keysDownRef.current.add('CONTROL') + } + if (event.metaKey) { + keysDownRef.current.add('META') + } + if (event.altKey) { + keysDownRef.current.add('ALT') + } + if (event.shiftKey) { + keysDownRef.current.add('SHIFT') + } + + if (keyDownTimeoutRef.current === -1) { + keyDownTimeoutRef.current = setTimeout(() => { + handleKeyupEvent() + }, shortcutTimeout ?? DEFAULT_TIMEOUT) } }, [])