From 285017647b6ceeff4cc4e8e12feb71b5fb10fc42 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Thu, 2 May 2024 14:24:50 +0530 Subject: [PATCH] feat: remove timer --- app/javascript/shared/helpers/keybindings.js | 29 ++------------------ 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/app/javascript/shared/helpers/keybindings.js b/app/javascript/shared/helpers/keybindings.js index 38e7520a3..a0cc34674 100644 --- a/app/javascript/shared/helpers/keybindings.js +++ b/app/javascript/shared/helpers/keybindings.js @@ -55,9 +55,6 @@ export function createKeybindingsHandler(keyBindingMap) { return [parseKeybinding(key), keyBindingMap[key]]; }); - let possibleMatches = new Map(); - let timer = null; - return event => { if (!(event instanceof KeyboardEvent)) { return; @@ -66,32 +63,12 @@ export function createKeybindingsHandler(keyBindingMap) { // eslint-disable-next-line no-console console.log(event.key, event.code, event.getModifierState('Control')); - keyBindings.forEach(keyBinding => { - let sequence = keyBinding[0]; - let callback = keyBinding[1]; + keyBindings.forEach(([key, callback]) => { + let expectedPress = parseKeybinding(key); - let prev = possibleMatches.get(sequence); - let remainingExpectedPresses = prev ?? sequence; - let currentExpectedPress = remainingExpectedPresses[0]; - - let matches = match(event, currentExpectedPress); - - if (!matches) { - if (!getModifierState(event, event.key)) { - possibleMatches.delete(sequence); - } - } else if (remainingExpectedPresses.length > 1) { - possibleMatches.set(sequence, remainingExpectedPresses.slice(1)); - } else { - possibleMatches.delete(sequence); + if (match(event, expectedPress)) { callback(event); } }); - - if (timer) { - clearTimeout(timer); - } - - timer = setTimeout(possibleMatches.clear.bind(possibleMatches), 1000); }; }