From ddeae60854dc59187668b6264de6a6dcb57d0f60 Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Thu, 20 May 2021 18:32:53 +0200 Subject: [PATCH] Instead of timeouts, make non-related keypresses cancel shortcut sequences --- ts/lib/shortcuts.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/ts/lib/shortcuts.ts b/ts/lib/shortcuts.ts index 5c83f2efa..07c425e67 100644 --- a/ts/lib/shortcuts.ts +++ b/ts/lib/shortcuts.ts @@ -100,8 +100,6 @@ function check( ); } -const shortcutTimeoutMs = 400; - function innerShortcut( lastEvent: KeyboardEvent, callback: (event: KeyboardEvent) => void, @@ -119,14 +117,12 @@ function innerShortcut( if (check(event, optionalModifiers, nextKey)) { innerShortcut(event, callback, optionalModifiers, ...restKeys); clearTimeout(interval); + } else if (event.location === 0) { + // Any non-modifier key will cancel the shortcut sequence + document.removeEventListener("keydown", handler); } }; - interval = setTimeout( - (): void => document.removeEventListener("keydown", handler), - shortcutTimeoutMs - ); - document.addEventListener("keydown", handler, { once: true }); } }