diff --git a/components/layout/SearchDialog.vue b/components/layout/SearchDialog.vue index f90df368..523dd86d 100644 --- a/components/layout/SearchDialog.vue +++ b/components/layout/SearchDialog.vue @@ -2,19 +2,27 @@ - +
- + {{ subtitle }} @@ -67,6 +75,8 @@ const open = defineModel('open'); const mode = useColorMode(); +const activeSelect = ref(0); + const { Meta_K, Ctrl_K } = useMagicKeys({ passive: false, onEventFired(e) { @@ -84,6 +94,7 @@ const searchResult = ref(); watch( input, async (v) => { + activeSelect.value = 0; searchResult.value = (await searchContent(v)).value; }, ); @@ -97,4 +108,20 @@ const { navigation } = useContent(); function getItemIcon(path: string) { return navKeyFromPath(path, 'icon', navigation.value); } + +watch(activeSelect, (value) => { + document.querySelector(`[id="${value}"]`)?.scrollIntoView({ block: 'nearest' }); +}); + +function handleEnter() { + if (searchResult.value[activeSelect.value]?.id) { + navigateTo(searchResult.value[activeSelect.value].id); + open.value = false; + } +} + +function handleNavigate(delta: -1 | 1) { + if (activeSelect.value + delta >= 0 && activeSelect.value + delta < searchResult.value.length) + activeSelect.value += delta; +}