summaryrefslogtreecommitdiff
path: root/ext/js/input
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-09-26 18:14:00 -0400
committerGitHub <noreply@github.com>2021-09-26 18:14:00 -0400
commitc364714c8188ab1503b53b096a70b1fd5b6b3055 (patch)
tree5f3a2af8b3ec19dbe3dfc88514f2b87e1a4bfc60 /ext/js/input
parentd739ccd63f0554f0f880e7463355dd5c4ff166e4 (diff)
Fix hotkey input field conflict (#1963)
* Move comment * Add DocumentUtil.isInputElement * Use DocumentUtil.isInputElement * Fix simple hotkeys (shift or no modifier) preventing text field input * Improve input detection * Validate key is an input character before blocking hotkey * Simplify * Fix incorrect property
Diffstat (limited to 'ext/js/input')
-rw-r--r--ext/js/input/hotkey-handler.js21
1 files changed, 16 insertions, 5 deletions
diff --git a/ext/js/input/hotkey-handler.js b/ext/js/input/hotkey-handler.js
index 8388302d..6c63aebb 100644
--- a/ext/js/input/hotkey-handler.js
+++ b/ext/js/input/hotkey-handler.js
@@ -153,11 +153,10 @@ class HotkeyHandler extends EventDispatcher {
// Private
_onKeyDown(e) {
- const key = e.code;
- const hotkeyInfo = this._hotkeys.get(key);
+ const hotkeyInfo = this._hotkeys.get(e.code);
if (typeof hotkeyInfo !== 'undefined') {
const eventModifiers = DocumentUtil.getActiveModifiers(e);
- if (this._invokeHandlers(eventModifiers, hotkeyInfo)) {
+ if (this._invokeHandlers(eventModifiers, hotkeyInfo, e.key)) {
e.preventDefault();
return;
}
@@ -165,9 +164,9 @@ class HotkeyHandler extends EventDispatcher {
this.trigger('keydownNonHotkey', e);
}
- _invokeHandlers(modifiers, hotkeyInfo) {
+ _invokeHandlers(modifiers, hotkeyInfo, key) {
for (const {modifiers: handlerModifiers, action, argument} of hotkeyInfo.handlers) {
- if (!this._areSame(handlerModifiers, modifiers)) { continue; }
+ if (!this._areSame(handlerModifiers, modifiers) || !this._isHotkeyPermitted(modifiers, key)) { continue; }
const actionHandler = this._actions.get(action);
if (typeof actionHandler !== 'undefined') {
@@ -223,4 +222,16 @@ class HotkeyHandler extends EventDispatcher {
this._eventListeners.removeAllEventListeners();
}
}
+
+ _isHotkeyPermitted(modifiers, key) {
+ return !(
+ (modifiers.length === 0 || (modifiers.length === 1 && modifiers[0] === 'shift')) &&
+ DocumentUtil.isInputElementFocused() &&
+ this._isKeyCharacterInput(key)
+ );
+ }
+
+ _isKeyCharacterInput(key) {
+ return key.length === 1;
+ }
}