aboutsummaryrefslogtreecommitdiff
path: root/ext/js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-02-19 21:20:58 -0500
committerGitHub <noreply@github.com>2021-02-19 21:20:58 -0500
commitb9e92a2528ff7cf85fb56ab4bc3b23eea4d512e2 (patch)
treecd0e4f6188f949553e739118cb885255077a09f2 /ext/js
parent1e927dd66e24b72ac3ba129dfb578746ce896ce2 (diff)
Improve key press to focus the search query input (#1424)
Diffstat (limited to 'ext/js')
-rw-r--r--ext/js/display/search-display-controller.js20
1 files changed, 18 insertions, 2 deletions
diff --git a/ext/js/display/search-display-controller.js b/ext/js/display/search-display-controller.js
index c8025d62..bf75e928 100644
--- a/ext/js/display/search-display-controller.js
+++ b/ext/js/display/search-display-controller.js
@@ -109,12 +109,15 @@ class SearchDisplayController {
}
_onKeyDown(e) {
+ const {activeElement} = document;
if (
- document.activeElement !== this._queryInput &&
+ activeElement !== this._queryInput &&
+ !this._isElementInput(activeElement) &&
!e.ctrlKey &&
!e.metaKey &&
!e.altKey &&
- e.key.length === 1
+ e.key.length === 1 &&
+ e.key !== ' '
) {
this._queryInput.focus({preventScroll: true});
}
@@ -425,4 +428,17 @@ class SearchDisplayController {
document.documentElement.dataset.searchMode = (mode !== null ? mode : '');
this._updateClipboardMonitorEnabled();
}
+
+ _isElementInput(element) {
+ if (element === null) { return false; }
+ switch (element.tagName.toLowerCase()) {
+ case 'input':
+ case 'textarea':
+ case 'button':
+ case 'select':
+ return true;
+ }
+ if (element.contentEditable) { return true; }
+ return false;
+ }
}