mirror of
https://github.com/ankitects/anki.git
synced 2025-09-25 01:06:35 -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(
|
function innerShortcut(
|
||||||
lastEvent: KeyboardEvent,
|
lastEvent: KeyboardEvent,
|
||||||
callback: (event: KeyboardEvent) => void,
|
callback: (event: KeyboardEvent) => void,
|
||||||
|
@ -119,14 +117,12 @@ function innerShortcut(
|
||||||
if (check(event, optionalModifiers, nextKey)) {
|
if (check(event, optionalModifiers, nextKey)) {
|
||||||
innerShortcut(event, callback, optionalModifiers, ...restKeys);
|
innerShortcut(event, callback, optionalModifiers, ...restKeys);
|
||||||
clearTimeout(interval);
|
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 });
|
document.addEventListener("keydown", handler, { once: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue