File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -34,36 +34,30 @@ import Fuse from '{{ "fuse.min.mjs" | relURL }}'
3434 input . addEventListener ( 'focus' , init ) ;
3535 input . addEventListener ( 'keyup' , search ) ;
3636
37- document . addEventListener ( 'keypress ' , focusSearchFieldOnKeyPress ) ;
37+ document . addEventListener ( 'keydown ' , focusOnKeyDown ) ;
3838
3939 /**
40- * @param {Event } event
40+ * @param {KeyboardEvent } event
4141 */
42- function focusSearchFieldOnKeyPress ( event ) {
43- if ( event . target . value !== undefined ) {
42+ function focusOnKeyDown ( event ) {
43+ if ( event . key === 'k' && ( event . metaKey || event . ctrlKey ) ) {
44+ event . preventDefault ( ) ;
45+ input . focus ( ) ;
4446 return ;
4547 }
4648
4749 if ( input === document . activeElement ) {
4850 return ;
4951 }
5052
51- const characterPressed = String . fromCharCode ( event . charCode ) ;
52- if ( ! isHotkey ( characterPressed ) ) {
53+ if ( event . target . value !== undefined ) {
5354 return ;
5455 }
5556
56- input . focus ( ) ;
57- event . preventDefault ( ) ;
58- }
59-
60- /**
61- * @param {String } character
62- * @returns {Boolean }
63- */
64- function isHotkey ( character ) {
65- const dataHotkeys = input . getAttribute ( 'data-hotkeys' ) || '' ;
66- return dataHotkeys . indexOf ( character ) >= 0 ;
57+ if ( event . key === '/' ) {
58+ event . preventDefault ( ) ;
59+ input . focus ( ) ;
60+ }
6761 }
6862
6963 function init ( ) {
Original file line number Diff line number Diff line change 33 < input id ="book-search-input " type ="text "
44 placeholder ="{{ partial "docs /text/i18n" "Search" }}"
55 aria-label="{{ partial "docs /text/i18n" "Search" }}"
6- maxlength="64 " data-hotkeys =" s/ " />
6+ maxlength="64 " />
77 < div class ="book-search-spinner hidden "> </ div >
88 < ul id ="book-search-results "> </ ul >
99</ div >
You can’t perform that action at this time.
0 commit comments