fix various unwanted focus issues on search page

Don't focus input if a modifier or specific keys are pressed
This commit is contained in:
siikamiika 2019-10-26 03:26:24 +03:00
parent a716a52cab
commit 3a70346eb3

View File

@ -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});
}
}