1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-06-27 16:36:00 +00:00

call preventDefault() when the user is trying to enter a keyboard shortcut

Keyboard shortcuts might conflict with Firefox’s "Find as you type" feature.
This commit is contained in:
Adam Hess 2019-10-06 16:24:39 -07:00 committed by Frédéric Guillot
parent bf2ceded96
commit 02dbe3ef2e
2 changed files with 17 additions and 10 deletions

View file

@ -2,19 +2,23 @@ class KeyboardHandler {
constructor() {
this.queue = [];
this.shortcuts = {};
this.triggers = [];
}
on(combination, callback) {
this.shortcuts[combination] = callback;
this.triggers.push(combination.split(" ")[0]);
}
listen() {
document.onkeydown = (event) => {
if (this.isEventIgnored(event) || this.isModifierKeyDown(event)) {
let key = this.getKey(event);
if (this.isEventIgnored(event, key) || this.isModifierKeyDown(event)) {
return;
} else {
event.preventDefault();
}
let key = this.getKey(event);
this.queue.push(key);
for (let combination in this.shortcuts) {
@ -39,8 +43,11 @@ class KeyboardHandler {
};
}
isEventIgnored(event) {
return event.target.tagName === "INPUT" || event.target.tagName === "TEXTAREA";
isEventIgnored(event, key) {
return event.target.tagName === "INPUT" ||
event.target.tagName === "TEXTAREA" ||
(this.queue.length < 1 && !this.triggers.includes(key));
}
isModifierKeyDown(event) {