From 15c66e2b01cadc616b1db64a74928209dee46873 Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Fri, 28 Jan 2022 18:19:32 +0100 Subject: [PATCH] Ignore "/" key handling if search box is focused Fixes a side effect of https://github.com/iv-org/invidious/pull/2814 See: https://github.com/iv-org/invidious/issues/2791#issuecomment-1018264144 --- assets/js/handlers.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/assets/js/handlers.js b/assets/js/handlers.js index a417fccae..d3957b893 100644 --- a/assets/js/handlers.js +++ b/assets/js/handlers.js @@ -146,7 +146,17 @@ // Handle keypresses window.addEventListener('keydown', (event) => { // Ignore modifier keys - if (event.ctrlKey || event.metaKey) { return; } + if (event.ctrlKey || event.metaKey) return; + + // Ignore shortcuts if any text input is focused + let focused_tag = document.activeElement.tagName.toLowerCase(); + let focused_type = document.activeElement.type.toLowerCase(); + let allowed = /^(button|checkbox|file|radio|submit)$/; + + if (focused_tag === "textarea" || + (focused_tag === "input" && !focused_type.match(allowed)) + ) + return; // Focus search bar on '/' if (event.key == "/") {