Skip to content

Commit 2289f98

Browse files
authored
Merge pull request #2846 from iv-org/SamantazFox-fix-search-focus-js
Ignore "/" key handling if search box is focused
2 parents 49edf0e + 15c66e2 commit 2289f98

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

assets/js/handlers.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,17 @@
146146
// Handle keypresses
147147
window.addEventListener('keydown', (event) => {
148148
// Ignore modifier keys
149-
if (event.ctrlKey || event.metaKey) { return; }
149+
if (event.ctrlKey || event.metaKey) return;
150+
151+
// Ignore shortcuts if any text input is focused
152+
let focused_tag = document.activeElement.tagName.toLowerCase();
153+
let focused_type = document.activeElement.type.toLowerCase();
154+
let allowed = /^(button|checkbox|file|radio|submit)$/;
155+
156+
if (focused_tag === "textarea" ||
157+
(focused_tag === "input" && !focused_type.match(allowed))
158+
)
159+
return;
150160

151161
// Focus search bar on '/'
152162
if (event.key == "/") {

0 commit comments

Comments
 (0)