From eb9d262c992c0ce0841ce8ce8ab829e486e5c2ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Fri, 10 Dec 2021 00:52:51 +0100 Subject: Only focus searchbox on '/' when sensible. --- static/script.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'static') diff --git a/static/script.ts b/static/script.ts index 34443b16..f243dd67 100644 --- a/static/script.ts +++ b/static/script.ts @@ -255,11 +255,12 @@ window.addEventListener('load', function() { }); document.addEventListener('keydown', function(event) { - if (event.key == '/') { - let searchbox = document.querySelector('.simplesearch [name=q]') as HTMLInputElement - // focuses the input, and selects all the text in it - searchbox.select(); - event.preventDefault(); - } + if (event.key !== '/') return; + if ('value' in (event.target as any)) return; + + let searchbox = document.querySelector('.simplesearch [name=q]') as HTMLInputElement + // focuses the input, and selects all the text in it + searchbox.select(); + event.preventDefault(); }); }) -- cgit v1.2.3