Search key handling refactor (#1233)
* Move super invocation * Move active element check * Simplify key handling * Remove unused
This commit is contained in:
parent
351d9b2e8e
commit
33aeae4110
@ -18,7 +18,6 @@
|
|||||||
/* global
|
/* global
|
||||||
* ClipboardMonitor
|
* ClipboardMonitor
|
||||||
* Display
|
* Display
|
||||||
* DocumentUtil
|
|
||||||
* api
|
* api
|
||||||
* wanakana
|
* wanakana
|
||||||
*/
|
*/
|
||||||
@ -43,20 +42,6 @@ class DisplaySearch extends Display {
|
|||||||
getText: async () => (await api.clipboardGet())
|
getText: async () => (await api.clipboardGet())
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this._onKeyDownIgnoreKeys = new Map([
|
|
||||||
['ANY_MOD', new Set([
|
|
||||||
'Tab', 'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'PageDown', 'PageUp', 'Home', 'End', 'Enter', 'Escape',
|
|
||||||
'F1', 'F2', 'F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'F9', 'F10',
|
|
||||||
'F11', 'F12', 'F13', 'F14', 'F15', 'F16', 'F17', 'F18', 'F19', 'F20',
|
|
||||||
'F21', 'F22', 'F23', 'F24'
|
|
||||||
])],
|
|
||||||
['Control', new Set(['C', 'A', 'Z', 'Y', 'X', 'F', 'G'])],
|
|
||||||
['Meta', new Set(['C', 'A', 'Z', 'Y', 'X', 'F', 'G'])],
|
|
||||||
['OS', new Set()],
|
|
||||||
['Alt', new Set()],
|
|
||||||
['AltGraph', new Set()],
|
|
||||||
['Shift', new Set()]
|
|
||||||
]);
|
|
||||||
this.autoPlayAudioDelay = 0;
|
this.autoPlayAudioDelay = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,27 +87,14 @@ class DisplaySearch extends Display {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onKeyDown(e) {
|
onKeyDown(e) {
|
||||||
const key = DocumentUtil.getKeyFromEvent(e);
|
if (
|
||||||
const ignoreKeys = this._onKeyDownIgnoreKeys;
|
!super.onKeyDown(e) &&
|
||||||
|
document.activeElement !== this._queryInput &&
|
||||||
const activeModifierMap = new Map([
|
!e.ctrlKey &&
|
||||||
['Control', e.ctrlKey],
|
!e.metaKey &&
|
||||||
['Meta', e.metaKey],
|
!e.altKey &&
|
||||||
['Shift', e.shiftKey],
|
e.key.length === 1
|
||||||
['Alt', e.altKey],
|
) {
|
||||||
['ANY_MOD', true]
|
|
||||||
]);
|
|
||||||
|
|
||||||
let preventFocus = false;
|
|
||||||
for (const [modifier, keys] of ignoreKeys.entries()) {
|
|
||||||
const modifierActive = activeModifierMap.get(modifier);
|
|
||||||
if (key === modifier || (modifierActive && keys.has(key))) {
|
|
||||||
preventFocus = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!super.onKeyDown(e) && !preventFocus && document.activeElement !== this._queryInput) {
|
|
||||||
this._queryInput.focus({preventScroll: true});
|
this._queryInput.focus({preventScroll: true});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user