mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
Instead of timeouts, make non-related keypresses cancel shortcut sequences
This commit is contained in:
parent
ae19ed527d
commit
ddeae60854
1 changed files with 3 additions and 7 deletions
|
@ -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 });
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue