docs/sphinx: add 's' keyboard binding to focus search
authorMarc-André Lureau <marcandre.lureau@redhat.com>
Fri, 8 Oct 2021 21:47:56 +0000 (01:47 +0400)
committerMarc-André Lureau <marcandre.lureau@redhat.com>
Mon, 8 Nov 2021 08:27:23 +0000 (12:27 +0400)
This is pretty ubiquitous. ('/' is already taken by some browsers for
quick search)

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: John Snow <jsnow@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
docs/conf.py
docs/sphinx-static/custom.js [new file with mode: 0644]

index f536483bc3d50e3cb2d29f1141b1d0cb87364e5e..3161b8b127c6650371a2165aee0e386dfdc4b198 100644 (file)
@@ -182,6 +182,10 @@ html_css_files = [
     'theme_overrides.css',
 ]
 
+html_js_files = [
+    'custom.js',
+]
+
 html_context = {
     "display_gitlab": True,
     "gitlab_user": "qemu-project",
diff --git a/docs/sphinx-static/custom.js b/docs/sphinx-static/custom.js
new file mode 100644 (file)
index 0000000..71a8605
--- /dev/null
@@ -0,0 +1,9 @@
+document.addEventListener('keydown', (event) => {
+    // find a better way to look it up?
+    let search_input = document.getElementsByName('q')[0];
+
+    if (event.code === 'KeyS' && document.activeElement !== search_input) {
+        event.preventDefault();
+        search_input.focus();
+    }
+});