From 77fa4787bd26b5193a5cc72226c1a3469f91ba11 Mon Sep 17 00:00:00 2001 From: gemmaro Date: Sat, 24 Sep 2022 23:29:51 +0900 Subject: [ruby/rdoc] Add keydown event listener to focus on search field https://github.com/ruby/rdoc/commit/db62e47df2 --- lib/rdoc/generator/template/darkfish/js/darkfish.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'lib/rdoc/generator/template/darkfish/js/darkfish.js') diff --git a/lib/rdoc/generator/template/darkfish/js/darkfish.js b/lib/rdoc/generator/template/darkfish/js/darkfish.js index d0c9467751..19a85c54e1 100644 --- a/lib/rdoc/generator/template/darkfish/js/darkfish.js +++ b/lib/rdoc/generator/template/darkfish/js/darkfish.js @@ -78,7 +78,20 @@ function hookSearch() { search.scrollIntoView = search.scrollInWindow; }; +function hookFocus() { + document.addEventListener("keydown", (event) => { + if (document.activeElement.tagName === 'INPUT') { + return; + } + if (event.key === "/") { + event.preventDefault(); + document.querySelector('#search-field').focus(); + } + }); +} + document.addEventListener('DOMContentLoaded', function() { hookSourceViews(); hookSearch(); + hookFocus(); }); -- cgit v1.2.3