File tree Expand file tree Collapse file tree 2 files changed +28
-10
lines changed
Expand file tree Collapse file tree 2 files changed +28
-10
lines changed Original file line number Diff line number Diff line change @@ -47,22 +47,36 @@ if (import.meta.server) {
4747 setJsonLd (createWebSiteSchema ())
4848}
4949
50+ function focusSearchOrNavigate() {
51+ const searchInput = document .querySelector <HTMLInputElement >(
52+ ' input[type="search"], input[name="q"]' ,
53+ )
54+
55+ if (searchInput ) {
56+ searchInput .focus ()
57+ return
58+ }
59+
60+ router .push ({ name: ' search' })
61+ }
62+
5063onKeyDown (
5164 ' /' ,
5265 e => {
5366 if (isEditableElement (e .target )) return
5467 e .preventDefault ()
68+ focusSearchOrNavigate ()
69+ },
70+ { dedupe: true },
71+ )
5572
56- const searchInput = document .querySelector <HTMLInputElement >(
57- ' input[type="search"], input[name="q"]' ,
58- )
59-
60- if (searchInput ) {
61- searchInput .focus ()
62- return
63- }
64-
65- router .push ({ name: ' search' })
73+ onKeyDown (
74+ // Explicitly check Ctrl+K for broader compatibility (especially Firefox)
75+ e => e .ctrlKey && e .key === ' k' ,
76+ e => {
77+ if (isEditableElement (e .target )) return
78+ e .preventDefault ()
79+ focusSearchOrNavigate ()
6680 },
6781 { dedupe: true },
6882)
Original file line number Diff line number Diff line change @@ -48,6 +48,10 @@ const showModal = () => modalRef.value?.showModal?.()
4848 <kbd class =" kbd" >/</kbd >
4949 <span >{{ $t('shortcuts.focus_search') }}</span >
5050 </li >
51+ <li class =" flex gap-2 items-center" >
52+ <kbd class =" kbd" >Ctrl</kbd >+<kbd class =" kbd" >K</kbd >
53+ <span >{{ $t('shortcuts.focus_search') }}</span >
54+ </li >
5155 <li class =" flex gap-2 items-center" >
5256 <kbd class =" kbd" >?</kbd >
5357 <span >{{ $t('shortcuts.show_kbd_hints') }}</span >
You can’t perform that action at this time.
0 commit comments