diff options
author | Adam Hess <adamhess1991@gmail.com> | 2019-10-06 16:24:39 -0700 |
---|---|---|
committer | Frédéric Guillot <fred@miniflux.net> | 2019-10-06 16:24:39 -0700 |
commit | 02dbe3ef2edaa40658862c1c92e73730c8e75ee1 (patch) | |
tree | 250d5d864a505b0fa9c6e34dc078a4d546d0fd0a /ui/static/js/keyboard_handler.js | |
parent | bf2ceded96139ccff66ab8a78fefa1ec0c8be43f (diff) |
call preventDefault() when the user is trying to enter a keyboard shortcut
Keyboard shortcuts might conflict with Firefox’s "Find as you type" feature.
Diffstat (limited to 'ui/static/js/keyboard_handler.js')
-rw-r--r-- | ui/static/js/keyboard_handler.js | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/ui/static/js/keyboard_handler.js b/ui/static/js/keyboard_handler.js index ecf1f44..718a4ee 100644 --- a/ui/static/js/keyboard_handler.js +++ b/ui/static/js/keyboard_handler.js @@ -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) { |