diff --git a/docs/zh/guide/ssr-compat.md b/docs/zh/guide/ssr-compat.md index 0e980f4a9efd..59da3fab5879 100644 --- a/docs/zh/guide/ssr-compat.md +++ b/docs/zh/guide/ssr-compat.md @@ -48,7 +48,7 @@ if (!import.meta.env.SSR) { } ``` -因为 [`Theme.enhanceApp`](/guide/custom-theme#theme-interface) 可以是异步的,所以可以有条件地导入并注册访问浏览器 API 的 Vue 插件: +因为 [`Theme.enhanceApp`](./custom-theme#theme-interface) 可以是异步的,所以可以有条件地导入并注册访问浏览器 API 的 Vue 插件: ```js // .vitepress/theme/index.js diff --git a/src/client/theme-default/components/VPLocalSearchBox.vue b/src/client/theme-default/components/VPLocalSearchBox.vue index 15a62efe01b3..010e32c768a7 100644 --- a/src/client/theme-default/components/VPLocalSearchBox.vue +++ b/src/client/theme-default/components/VPLocalSearchBox.vue @@ -299,26 +299,39 @@ function scrollToSelectedResult() { }) } -onKeyStroke('ArrowUp', (event) => { - event.preventDefault() - selectedIndex.value-- - if (selectedIndex.value < 0) { - selectedIndex.value = results.value.length - 1 - } +function goRelativeItem(offset: number) { + const resNum = results.value.length + selectedIndex.value = (selectedIndex.value + resNum + (offset % resNum)) % resNum disableMouseOver.value = true scrollToSelectedResult() +} + +onKeyStroke('ArrowUp', (event) => { + event.preventDefault() + goRelativeItem(-1) }) onKeyStroke('ArrowDown', (event) => { event.preventDefault() - selectedIndex.value++ - if (selectedIndex.value >= results.value.length) { - selectedIndex.value = 0 - } - disableMouseOver.value = true - scrollToSelectedResult() + goRelativeItem(1) }) +if (document.documentElement.classList.contains('mac')) { + onKeyStroke('n', (event) => { + if (event.ctrlKey) { + event.preventDefault() + goRelativeItem(1) + } + }) + + onKeyStroke('p', (event) => { + if (event.ctrlKey) { + event.preventDefault() + goRelativeItem(-1) + } + }) +} + const router = useRouter() onKeyStroke('Enter', (e) => { @@ -540,9 +553,18 @@ function formMarkRegex(terms: Set) { + / + + ctrl-p + + and + / + + ctrl-n + {{ translate('modal.footer.navigateText') }}