Skip to content

Commit 024eab2

Browse files
committed
fix(plugin-docsearch): open on ctrl+k when page first loads
The `{ once: true }` prevented the listener from properly attaching and listening for a whole ctrl+k event. It would exit early, causing the page to not function properly on first load.
1 parent 2c01d35 commit 024eab2

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

plugins/search/plugin-docsearch/src/client/composables/useDocSearchHotkeyListener.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,14 @@ import { useEventListener } from '@vueuse/core'
44
* Add hotkey listener, remove it after triggered
55
*/
66
export const useDocSearchHotkeyListener = (callback: () => void): void => {
7-
useEventListener(
8-
'keydown',
9-
(event) => {
10-
const isHotKeyBind = event.key === 'k' && (event.ctrlKey || event.metaKey)
11-
const isSlashKey = event.key === '/'
7+
useEventListener('keydown', (event) => {
8+
const isHotKeyBind = event.key === 'k' && (event.ctrlKey || event.metaKey)
9+
const isSlashKey = event.key === '/'
1210

13-
if (!isSlashKey && !isHotKeyBind) {
14-
return
15-
}
16-
17-
event.preventDefault()
18-
callback()
19-
},
20-
{ once: true },
21-
)
11+
if (!isSlashKey && !isHotKeyBind) {
12+
return
13+
}
14+
event.preventDefault()
15+
callback()
16+
})
2217
}

0 commit comments

Comments
 (0)