diff options
author | siikamiika <siikamiika@users.noreply.github.com> | 2019-10-26 03:26:24 +0300 |
---|---|---|
committer | siikamiika <siikamiika@users.noreply.github.com> | 2019-10-26 03:26:24 +0300 |
commit | 3a70346eb37ce234e49460ed0c97acb3affe68cc (patch) | |
tree | ab16d894e2d5f7d7eaf0b75593bc55185160f33c | |
parent | a716a52cab143ae2e02b54c2f075a8731de16193 (diff) |
fix various unwanted focus issues on search page
Don't focus input if a modifier or specific keys are pressed
-rw-r--r-- | ext/bg/js/search.js | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js index 5c0bffed..f0bbf203 100644 --- a/ext/bg/js/search.js +++ b/ext/bg/js/search.js @@ -96,7 +96,34 @@ class DisplaySearch extends Display { } onKeyDown(e) { - if (!super.onKeyDown(e)) { + const key = Display.getKeyFromEvent(e); + + let activeModifierMap = { + 'Control': e.ctrlKey, + 'Meta': e.metaKey + }; + // true if no known modifier is pressed + activeModifierMap[undefined] = !Object.values(activeModifierMap).includes(true); + + const ignoreKeys = { + undefined: ['Tab'], + 'Control': ['C', 'A', 'V'], + 'Meta': ['C', 'A', 'V'], + 'OS': [], + 'Alt': [], + 'Shift': [] + } + + let preventFocus = false; + for (const [modifier, keys] of Object.entries(ignoreKeys)) { + const modifierActive = activeModifierMap[modifier]; + if (key === modifier || (modifierActive && keys.includes(key))) { + preventFocus = true; + break; + } + } + + if (!super.onKeyDown(e) && !preventFocus) { this.query.focus({preventScroll: true}); } } |