[gi-docgen: 1/2] templates/basic/main.js: Don't grab 's' keybinding when search input is hidden




commit e4a5f01c39aa0e0aaaef17a890c011b79028f5e0
Author: Vanadiae <vanadiae35 gmail com>
Date:   Thu Aug 5 15:01:03 2021 +0000

    templates/basic/main.js: Don't grab 's' keybinding when search input is hidden
    
    Fixes #97

 gidocgen/templates/basic/main.js | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
---
diff --git a/gidocgen/templates/basic/main.js b/gidocgen/templates/basic/main.js
index 7a3f45d..09ee480 100644
--- a/gidocgen/templates/basic/main.js
+++ b/gidocgen/templates/basic/main.js
@@ -144,8 +144,12 @@ function attachCopyHandlers() {
 
 function onKeyDown(event) {
     let search_input = document.querySelector("#search-input");
+    // We don't want to try to focus the search input if it isn't visible. That way
+    // we avoid the preventDefault(), hence allowing devhelp to use S as mnemonic.
+    let potentially_hidden_parent = search_input.closest('.hidden, .devhelp-hidden');
 
-    if (event.code === "KeyS" && document.activeElement !== search_input) {
+    if (window.getComputedStyle(potentially_hidden_parent).display !== 'none' &&
+        event.code === "KeyS" && document.activeElement !== search_input) {
         event.preventDefault();
         search_input.focus();
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]