Commit bdf64bf47b

bdf64bf47b847b6532f7e777a73b7647c3cd4118

parent: f17cadfd87

Unsigned

Duck <57977673+woducku@users.noreply.github.com> · 2026-07-31 16:56 UTC

Update Search.vue

Layout: unified · split

docs/.vitepress/theme/components/search/Search.vue +371 −123
@@ -16,6 +16,8 @@ import {
1616} from 'vue'
1717// @ts-ignore
1818import { pathToFile } from 'vitepress/dist/client/app/utils'
19// @ts-ignore
20import { RouterSymbol } from 'vitepress/dist/client/app/router'
1921
2022import {
2123 computedAsync,
@@ -31,71 +33,67 @@ import { AnimatePresence } from 'motion-v'
3133// @ts-ignore
3234import localSearchIndex from '@localSearchIndex'
3335
34import {
35 File,
36 Hash,
37 ArrowRight
38} from 'lucide-vue-next'
36import { ArrowRight, File, Hash } from 'lucide-vue-next'
3937
4038import Mark from 'mark.js/dist/mark.es6.js'
4139import { sidebar } from '../../../configs/constants'
42import type { PageLink } from '../../plugins/urlSearchPlugin'
4340import { LRUCache } from '../../composables/search/lru-cache'
4441import { createSearchTranslate } from '../../composables/search/translation'
4542import { useData } from '../../composables/search/use-data'
4643import { useEffects } from '../../composables/useEffects'
4744import { applyFavicons, useFavicons } from '../../composables/useFavicons'
4845import { registerGlobalComponents } from '../../globalComponents'
46import type { PageLink } from '../../plugins/urlSearchPlugin'
4947import {
5048 excerptPreload,
5149 ribbonStyle,
5250 saveHistoryEnabled,
5351 searchHistory,
52 type SearchHistoryEntry,
5453 searchMode,
5554 searchResultHighlightMode,
56 showDetailedList,
57 type SearchHistoryEntry,
58 type SearchSortMode
55 type SearchSortMode,
56 showDetailedList
5957} from '../../searchState'
6058import { enhanceAppWithTabs } from '../tabs'
6159
6260import type {
6361 FooterTranslations,
6462 ModalTranslations,
65 Result,
6663 PageGroupCount,
67 UrlResult,
64 Result,
65 SearchWorkerRequest,
6866 TextSearchWorkerPayload,
69 UrlSearchWorkerPayload,
70 SearchWorkerRequest
67 UrlResult,
68 UrlSearchWorkerPayload
7169} from './types'
7270
7371import {
72 buildResultHref,
7473 escapeHtml,
75 highlightUrl,
7674 formMarkRegex,
77 toHistoryPathHtml,
78 hasExcerptPreview,
79 getPageKey,
80 getDocId,
8175 getDocAnchor,
76 getDocId,
77 getPageKey,
8278 getPageLabel,
8379 getPageOrder,
84 buildResultHref,
80 getPageOrderEntries,
8581 getSearchResultHref,
82 hasExcerptPreview,
83 highlightUrl,
84 nextFrame,
8685 stripNonCloneable,
87 getPageOrderEntries,
88 nextFrame
86 toHistoryPathHtml
8987} from './utils'
9088
9189import { useSearchMotion } from './SearchMotion'
9290
9391import SearchBar from './SearchBar.vue'
94import SearchRibbon from './SearchRibbon.vue'
95import SearchPagination from './SearchPagination.vue'
96import SearchKeyboardShortcuts from './SearchKeyboardShortcuts.vue'
9792import SearchEmptyState from './SearchEmptyState.vue'
9893import SearchHistory from './SearchHistory.vue'
94import SearchKeyboardShortcuts from './SearchKeyboardShortcuts.vue'
95import SearchPagination from './SearchPagination.vue'
96import SearchRibbon from './SearchRibbon.vue'
9997import SearchSettings from './SearchSettings.vue'
10098
10199const showSearch = defineModel<boolean>()
@@ -106,8 +104,12 @@ const searchBarRef = ref<InstanceType<typeof SearchBar>>()
106104const ribbonRef = ref<InstanceType<typeof SearchRibbon>>()
107105
108106/* Refs exposed by SearchBar */
109const searchInput = computed(() => searchBarRef.value?.searchInput as HTMLInputElement | undefined)
110const settingsButtonRef = computed(() => searchBarRef.value?.settingsButtonRef as HTMLButtonElement | undefined)
107const searchInput = computed(() =>
108 searchBarRef.value?.searchInput as HTMLInputElement | undefined
109)
110const settingsButtonRef = computed(() =>
111 searchBarRef.value?.settingsButtonRef as HTMLButtonElement | undefined
112)
111113
112114/* Search */
113115const searchIndexData = shallowRef(localSearchIndex)
@@ -199,7 +201,9 @@ function saveToHistory(
199201 searchHistory.value = [
200202 { query: trimmed, mode, path, href, resultText },
201203 ...searchHistory.value.filter(
202 (h) => !(h.query === trimmed && h.mode === mode && (h.path ?? []).join('\n') === pathKey)
204 (h) =>
205 !(h.query === trimmed && h.mode === mode &&
206 (h.path ?? []).join('\n') === pathKey)
203207 )
204208 ]
205209}
@@ -241,7 +245,9 @@ const urlPageGroups = computed(() =>
241245 label: getPageLabel(group.key, pageMeta),
242246 count: group.count
243247 }))
244 .sort((a, b) => getPageOrder(a.key, pageMeta) - getPageOrder(b.key, pageMeta))
248 .sort((a, b) =>
249 getPageOrder(a.key, pageMeta) - getPageOrder(b.key, pageMeta)
250 )
245251)
246252
247253const urlFilteredMatches = computed((): PageLink[] => {
@@ -303,7 +309,9 @@ function goToUrlPage(p: number) {
303309 })
304310}
305311
306watch([urlFilterDebounced, urlActivePageFilter], () => { urlPage.value = 1 })
312watch([urlFilterDebounced, urlActivePageFilter], () => {
313 urlPage.value = 1
314})
307315
308316watch(urlMatches, () => {
309317 if (
@@ -392,7 +400,9 @@ let searchWorker: Worker | undefined
392400let searchWorkerRequestId = 0
393401let loadedWorkerIndexKey = ''
394402let preloadedSearchDataKey = ''
395let preloadSearchDataRequest: { key: string; promise: Promise<void> } | undefined
403let preloadSearchDataRequest:
404 | { key: string; promise: Promise<void> }
405 | undefined
396406const searchWorkerRequests = new Map<
397407 number,
398408 { resolve: (value: unknown) => void; reject: (reason?: unknown) => void }
@@ -402,11 +412,18 @@ function getMiniSearchWorkerConfig() {
402412 const miniSearch = theme.value.search?.provider === 'local'
403413 ? theme.value.search.options?.miniSearch
404414 : undefined
405 const rawSearchOptions = miniSearch?.searchOptions as Record<string, unknown> | undefined
415 const rawSearchOptions = miniSearch?.searchOptions as
416 | Record<string, unknown>
417 | undefined
406418 return {
407 options: stripNonCloneable(miniSearch?.options) as Record<string, unknown> | undefined,
408 searchOptions: stripNonCloneable(rawSearchOptions) as Record<string, unknown> | undefined,
409 useDefaultBoostDocument: typeof rawSearchOptions?.boostDocument === 'function'
419 options: stripNonCloneable(miniSearch?.options) as
420 | Record<string, unknown>
421 | undefined,
422 searchOptions: stripNonCloneable(rawSearchOptions) as
423 | Record<string, unknown>
424 | undefined,
425 useDefaultBoostDocument:
426 typeof rawSearchOptions?.boostDocument === 'function'
410427 }
411428}
412429
@@ -424,7 +441,8 @@ async function preloadSearchData(
424441
425442 const promise = (async () => {
426443 if (loadedWorkerIndexKey !== workerIndexKey) {
427 const indexJson = (await searchIndexData.value[localeIndexValue]?.())?.default
444 const indexJson = (await searchIndexData.value[localeIndexValue]?.())
445 ?.default
428446 await postSearchWorker<void>({
429447 type: 'load-index',
430448 localeIndex: localeIndexValue,
@@ -466,7 +484,12 @@ function ensureSearchWorker() {
466484 }
467485
468486 searchWorker.onmessage = (event: MessageEvent) => {
469 const data = event.data as { id: number; type: string; payload?: unknown; error?: string }
487 const data = event.data as {
488 id: number
489 type: string
490 payload?: unknown
491 error?: string
492 }
470493 const request = searchWorkerRequests.get(data.id)
471494 if (!request) return
472495 searchWorkerRequests.delete(data.id)
@@ -489,12 +512,17 @@ function postSearchWorker<T>(message: SearchWorkerRequest) {
489512
490513 const id = ++searchWorkerRequestId
491514 return new Promise<T>((resolve, reject) => {
492 searchWorkerRequests.set(id, { resolve: (value) => resolve(value as T), reject })
515 searchWorkerRequests.set(id, {
516 resolve: (value) => resolve(value as T),
517 reject
518 })
493519 worker.postMessage({ ...message, id })
494520 })
495521}
496522
497onMounted(() => { ensureSearchWorker() })
523onMounted(() => {
524 ensureSearchWorker()
525})
498526
499527onBeforeUnmount(() => {
500528 searchWorker?.terminate()
@@ -511,7 +539,14 @@ onBeforeUnmount(() => {
511539
512540// Watch: preload search data when search opens
513541watch(
514 () => [searchWorkerReady.value, showSearch.value, localeIndex.value, searchIndexVersion.value, searchWorkerConfigKey.value] as const,
542 () =>
543 [
544 searchWorkerReady.value,
545 showSearch.value,
546 localeIndex.value,
547 searchIndexVersion.value,
548 searchWorkerConfigKey.value
549 ] as const,
515550 async ([ready, isOpen, localeIndexValue, indexVersion, configKey]) => {
516551 if (!ready || !isOpen) return
517552 try {
@@ -525,17 +560,28 @@ watch(
525560
526561// Watch: URL search
527562watch(
528 () => [searchWorkerReady.value, showSearch.value, urlSearchMode.value, urlFilterDebounced.value] as const,
563 () =>
564 [
565 searchWorkerReady.value,
566 showSearch.value,
567 urlSearchMode.value,
568 urlFilterDebounced.value
569 ] as const,
529570 async ([ready, isOpen, active, query], _old, onCleanup) => {
530571 let canceled = false
531 onCleanup(() => { canceled = true })
572 onCleanup(() => {
573 canceled = true
574 })
532575 if (!active || !isOpen || !query.trim()) {
533576 urlMatches.value = []
534577 urlPageGroupCounts.value = []
535578 urlSearchLoading.value = false
536579 return
537580 }
538 if (!ready) { urlSearchLoading.value = false; return }
581 if (!ready) {
582 urlSearchLoading.value = false
583 return
584 }
539585 urlSearchLoading.value = true
540586 try {
541587 const payload = await postSearchWorker<UrlSearchWorkerPayload>({
@@ -575,7 +621,9 @@ const pageGroups = computed(() => {
575621
576622const filteredResults = computed(() => {
577623 if (!activePageFilter.value) return results.value
578 return results.value.filter((r) => getPageKey(r.id) === activePageFilter.value)
624 return results.value.filter((r) =>
625 getPageKey(r.id) === activePageFilter.value
626 )
579627})
580628
581629// Normal pagination
@@ -651,6 +699,7 @@ async function reapplyHighlights() {
651699 mark.value?.unmark({
652700 done: () => {
653701 mark.value?.markRegExp(formMarkRegex(currentTerms.value), {
702 filter: shouldMarkTextNode,
654703 done: () => resolve()
655704 })
656705 }
@@ -763,19 +812,39 @@ function buildDocExcerpt(docId: string): Promise<void> {
763812 enhanceAppWithTabs(app, { renderAll: true })
764813 registerGlobalComponents(app)
765814 app.provide(dataSymbol, vitePressData)
815 // Pages embed <Feedback>, which calls useRouter() in the excerpt app.
816 app.provide(RouterSymbol, router)
766817 Object.defineProperties(app.config.globalProperties, {
767 $frontmatter: { get() { return vitePressData.frontmatter.value } },
768 $params: { get() { return vitePressData.page.value.params } }
818 $frontmatter: {
819 get() {
820 return vitePressData.frontmatter.value
821 }
822 },
823 $params: {
824 get() {
825 return vitePressData.page.value.params
826 }
827 }
769828 })
770829 const div = document.createElement('div')
771830 try {
772831 const originalCreateElement = document.createElement
773 document.createElement = function (this: Document, ...args: Parameters<Document['createElement']>) {
832 document.createElement = function(
833 this: Document,
834 ...args: Parameters<Document['createElement']>
835 ) {
774836 const el = originalCreateElement.apply(this, args)
775 if (el instanceof HTMLImageElement) { el.loading = 'lazy'; el.decoding = 'async' }
837 if (el instanceof HTMLImageElement) {
838 el.loading = 'lazy'
839 el.decoding = 'async'
840 }
776841 return el
777842 } as typeof document.createElement
778 try { app.mount(div) } finally { document.createElement = originalCreateElement }
843 try {
844 app.mount(div)
845 } finally {
846 document.createElement = originalCreateElement
847 }
779848 const headings = div.querySelectorAll('h1, h2, h3, h4, h5, h6')
780849 headings.forEach((heading) => {
781850 const href = heading.querySelector('a')?.getAttribute('href')
@@ -783,7 +852,9 @@ function buildDocExcerpt(docId: string): Promise<void> {
783852 const anchor = hashIndex >= 0 ? href!.slice(hashIndex + 1) : ''
784853 if (!anchor) return
785854
786 const collapsible = heading.closest('details.custom-block') as HTMLDetailsElement | null
855 const collapsible = heading.closest('details.custom-block') as
856 | HTMLDetailsElement
857 | null
787858 if (collapsible) {
788859 collapsible.open = true
789860 map.set(anchor, collapsible.outerHTML)
@@ -792,7 +863,9 @@ function buildDocExcerpt(docId: string): Promise<void> {
792863
793864 let html = ''
794865 let node = heading as Element
795 while ((node = node.nextElementSibling!) && !/^h[1-6]$/i.test(node.tagName)) {
866 while (
867 (node = node.nextElementSibling!) && !/^h[1-6]$/i.test(node.tagName)
868 ) {
796869 html += (node as HTMLElement).outerHTML
797870 }
798871 map.set(anchor, html)
@@ -800,7 +873,9 @@ function buildDocExcerpt(docId: string): Promise<void> {
800873 } catch (e) {
801874 console.error('[search] excerpt render failed for', docId, e)
802875 } finally {
803 try { app.unmount() } catch { /* ignore */ }
876 try {
877 app.unmount()
878 } catch { /* ignore */ }
804879 }
805880 cache.set(docId, map)
806881 })()
@@ -828,7 +903,9 @@ async function fetchExcerpt(id: string) {
828903 }
829904}
830905
831watch(excerptPreload, () => { void buildVisibleExcerpts() })
906watch(excerptPreload, () => {
907 void buildVisibleExcerpts()
908})
832909
833910watch(results, () => {
834911 if (
@@ -839,19 +916,52 @@ watch(results, () => {
839916 }
840917})
841918
842watch(filterText, () => { enableNoResults.value = false })
919watch(filterText, () => {
920 enableNoResults.value = false
921})
843922
844923// Debounced text search
845924watchDebounced(
846 () => [searchWorkerReady.value, showSearch.value, localeIndex.value, searchIndexVersion.value, searchWorkerConfigKey.value, filterText.value, showDetailedList.value, searchMode.value] as const,
847 async ([ready, isOpen, localeIndexValue, indexVersion, configKey, filterTextValue, showDetailedListValue, mode], old, onCleanup) => {
848 if (old?.[2] !== localeIndexValue || old?.[3] !== indexVersion || old?.[4] !== configKey) {
925 () =>
926 [
927 searchWorkerReady.value,
928 showSearch.value,
929 localeIndex.value,
930 searchIndexVersion.value,
931 searchWorkerConfigKey.value,
932 filterText.value,
933 showDetailedList.value,
934 searchMode.value
935 ] as const,
936 async (
937 [
938 ready,
939 isOpen,
940 localeIndexValue,
941 indexVersion,
942 configKey,
943 filterTextValue,
944 showDetailedListValue,
945 mode
946 ],
947 old,
948 onCleanup
949 ) => {
950 if (
951 old?.[2] !== localeIndexValue || old?.[3] !== indexVersion ||
952 old?.[4] !== configKey
953 ) {
849954 cache.clear()
850955 }
851956 let canceled = false
852 onCleanup(() => { canceled = true })
957 onCleanup(() => {
958 canceled = true
959 })
853960 excerptBuildToken++
854 if (!ready || !isOpen) { textSearchLoading.value = false; return }
961 if (!ready || !isOpen) {
962 textSearchLoading.value = false
963 return
964 }
855965
856966 if (mode === 'url') {
857967 results.value = []
@@ -869,14 +979,18 @@ watchDebounced(
869979 } catch (error) {
870980 if (!canceled) {
871981 console.error('[search] text search index preload failed', error)
872 results.value = []; currentTerms.value = new Set()
873 enableNoResults.value = Boolean(searchQuery); textSearchLoading.value = false
982 results.value = []
983 currentTerms.value = new Set()
984 enableNoResults.value = Boolean(searchQuery)
985 textSearchLoading.value = false
874986 }
875987 return
876988 }
877989 if (!searchQuery) {
878 results.value = []; currentTerms.value = new Set()
879 enableNoResults.value = false; textSearchLoading.value = false
990 results.value = []
991 currentTerms.value = new Set()
992 enableNoResults.value = false
993 textSearchLoading.value = false
880994 return
881995 }
882996
@@ -891,8 +1005,10 @@ watchDebounced(
8911005 } catch (error) {
8921006 if (!canceled) {
8931007 console.error('[search] text search worker request failed', error)
894 results.value = []; currentTerms.value = new Set()
895 enableNoResults.value = true; textSearchLoading.value = false
1008 results.value = []
1009 currentTerms.value = new Set()
1010 enableNoResults.value = true
1011 textSearchLoading.value = false
8961012 }
8971013 return
8981014 }
@@ -902,14 +1018,24 @@ watchDebounced(
9021018 const terms = new Set(workerPayload.terms)
9031019 currentTerms.value = terms
9041020 enableNoResults.value = true
905 if (!_result.length) { results.value = []; textSearchLoading.value = false; return }
1021 if (!_result.length) {
1022 results.value = []
1023 textSearchLoading.value = false
1024 return
1025 }
9061026
9071027 const highlight = () =>
9081028 new Promise<void>((resolve) => {
909 if (!terms.size || !mark.value) { resolve(); return }
1029 if (!terms.size || !mark.value) {
1030 resolve()
1031 return
1032 }
9101033 mark.value.unmark({
9111034 done: () => {
912 mark.value?.markRegExp(formMarkRegex(terms), { done: () => resolve() })
1035 mark.value?.markRegExp(formMarkRegex(terms), {
1036 filter: shouldMarkTextNode,
1037 done: () => resolve()
1038 })
9131039 }
9141040 })
9151041 })
@@ -934,6 +1060,36 @@ watchDebounced(
9341060)
9351061
9361062// Excerpt centering
1063const findTargetLinkInExcerpt = (
1064 excerptElement: HTMLElement,
1065 linkTitle: string
1066) => {
1067 const links = excerptElement.querySelectorAll('a')
1068 const normalizedTitle = linkTitle.trim().toLowerCase()
1069 for (const link of links) {
1070 if (link.textContent?.trim().toLowerCase() === normalizedTitle) {
1071 return link
1072 }
1073 }
1074 return null
1075}
1076
1077// For pinned results, only mark text inside the target link so other substring matches are skipped.
1078const shouldMarkTextNode = (textNode: Text) => {
1079 const parent = textNode.parentElement
1080 if (!parent) return true
1081
1082 const resultEl = parent.closest('.result') as HTMLElement | null
1083 const linkTitle = resultEl?.dataset?.linkTitle
1084 if (!linkTitle) return true
1085
1086 const excerpt = parent.closest('.excerpt') as HTMLElement | null
1087 if (!excerpt) return true
1088
1089 const targetLink = findTargetLinkInExcerpt(excerpt, linkTitle)
1090 return targetLink ? targetLink.contains(textNode) : true
1091}
1092
9371093function centerExcerpts() {
9381094 const excerpts = el.value?.querySelectorAll('.result .excerpt') ?? []
9391095 for (let i = 0; i < excerpts.length; i++) {
@@ -944,20 +1100,18 @@ function centerExcerpts() {
9441100
9451101 let markNode: HTMLElement | null
9461102 if (linkTitle) {
947 const links = excerptElement.querySelectorAll('a')
948 let targetLink: HTMLAnchorElement | null = null
949 const normalizedTitle = linkTitle.trim().toLowerCase()
950 for (const link of links) {
951 if (link.textContent?.trim().toLowerCase() === normalizedTitle) {
952 targetLink = link
953 break
954 }
955 }
1103 const targetLink = findTargetLinkInExcerpt(excerptElement, linkTitle)
9561104 markNode = targetLink
957 ? (targetLink.querySelector('mark[data-markjs="true"]') as HTMLElement | null)
958 : (excerptElement.querySelector('mark[data-markjs="true"]') as HTMLElement | null)
1105 ? (targetLink.querySelector('mark[data-markjs="true"]') as
1106 | HTMLElement
1107 | null)
1108 : (excerptElement.querySelector('mark[data-markjs="true"]') as
1109 | HTMLElement
1110 | null)
9591111 } else {
960 markNode = excerptElement.querySelector('mark[data-markjs="true"]') as HTMLElement | null
1112 markNode = excerptElement.querySelector('mark[data-markjs="true"]') as
1113 | HTMLElement
1114 | null
9611115 }
9621116
9631117 if (!markNode) continue
@@ -968,17 +1122,23 @@ function centerExcerpts() {
9681122 offset += node.offsetTop
9691123 node = node.offsetParent as HTMLElement | null
9701124 }
971 const targetScrollTop = offset - viewportHeight / 2 + markNode.offsetHeight / 2
1125 const targetScrollTop = offset - viewportHeight / 2 +
1126 markNode.offsetHeight / 2
9721127 excerptElement.scrollTop = Math.max(0, targetScrollTop)
9731128 }
9741129}
9751130
9761131let centerHandle = 0
9771132
978function centerExcerptsUntilSettled(duration = searchAnimationsEnabled.value ? 450 : 0) {
1133function centerExcerptsUntilSettled(
1134 duration = searchAnimationsEnabled.value ? 450 : 0
1135) {
9791136 if (centerHandle) cancelAnimationFrame(centerHandle)
9801137 if (duration <= 0) {
981 centerHandle = requestAnimationFrame(() => { centerExcerpts(); centerHandle = 0 })
1138 centerHandle = requestAnimationFrame(() => {
1139 centerExcerpts()
1140 centerHandle = 0
1141 })
9821142 return
9831143 }
9841144 const start = performance.now()
@@ -986,7 +1146,7 @@ function centerExcerptsUntilSettled(duration = searchAnimationsEnabled.value ? 4
9861146 centerExcerpts()
9871147 if (performance.now() - start < duration) {
9881148 centerHandle = requestAnimationFrame(tick)
989 } else { centerHandle = 0 }
1149 } else centerHandle = 0
9901150 }
9911151 centerHandle = requestAnimationFrame(tick)
9921152}
@@ -1003,7 +1163,9 @@ function focusSearchInput(select = true) {
10031163 select && searchInput.value?.select()
10041164}
10051165
1006onMounted(() => { focusSearchInput() })
1166onMounted(() => {
1167 focusSearchInput()
1168})
10071169
10081170function onSearchBarClick(event: PointerEvent) {
10091171 if (event.pointerType === 'mouse') focusSearchInput()
@@ -1014,20 +1176,30 @@ const selectedIndex = ref(-1)
10141176const disableMouseOver = ref(true)
10151177
10161178const activeResultsLength = computed(() =>
1017 urlSearchMode.value ? filteredUrlResults.value.length : pagedResults.value.length
1179 urlSearchMode.value
1180 ? filteredUrlResults.value.length
1181 : pagedResults.value.length
10181182)
10191183
10201184watch(pagedResults, (r) => {
1021 if (!urlSearchMode.value) { selectedIndex.value = r.length ? 0 : -1; scrollToSelectedResult() }
1185 if (!urlSearchMode.value) {
1186 selectedIndex.value = r.length ? 0 : -1
1187 scrollToSelectedResult()
1188 }
10221189})
10231190
10241191watch(filteredUrlResults, (r) => {
1025 if (urlSearchMode.value) { selectedIndex.value = r.length ? 0 : -1; scrollToSelectedResult() }
1192 if (urlSearchMode.value) {
1193 selectedIndex.value = r.length ? 0 : -1
1194 scrollToSelectedResult()
1195 }
10261196})
10271197
10281198watch([pagedResults, filteredUrlResults, faviconsEnabled], () => {
10291199 if (!faviconsEnabled.value) return
1030 nextTick(() => { if (resultsEl.value) applyFavicons(resultsEl.value) })
1200 nextTick(() => {
1201 if (resultsEl.value) applyFavicons(resultsEl.value)
1202 })
10311203})
10321204
10331205function scrollToSelectedResult() {
@@ -1072,7 +1244,9 @@ function cyclePageTab(delta: number) {
10721244onKeyStroke('ArrowUp', (event) => {
10731245 event.preventDefault()
10741246 selectedIndex.value--
1075 if (selectedIndex.value < 0) selectedIndex.value = activeResultsLength.value - 1
1247 if (selectedIndex.value < 0) {
1248 selectedIndex.value = activeResultsLength.value - 1
1249 }
10761250 disableMouseOver.value = true
10771251 scrollToSelectedResult()
10781252})
@@ -1080,7 +1254,9 @@ onKeyStroke('ArrowUp', (event) => {
10801254onKeyStroke('ArrowDown', (event) => {
10811255 event.preventDefault()
10821256 selectedIndex.value++
1083 if (selectedIndex.value >= activeResultsLength.value + 1) selectedIndex.value = 0
1257 if (selectedIndex.value >= activeResultsLength.value + 1) {
1258 selectedIndex.value = 0
1259 }
10841260 disableMouseOver.value = true
10851261 scrollToSelectedResult()
10861262})
@@ -1108,9 +1284,13 @@ const router = useRouter()
11081284
11091285function navigateToUrlResult(item: UrlResult) {
11101286 saveToHistory(
1111 filterText.value, searchMode.value,
1112 [getPageLabel(item.pageId, pageMeta), ...item.titles, item.linkText].map(toHistoryPathHtml).filter(Boolean),
1113 buildResultHref(item.pageId, item.tabs, item.anchor), item.linkText
1287 filterText.value,
1288 searchMode.value,
1289 [getPageLabel(item.pageId, pageMeta), ...item.titles, item.linkText].map(
1290 toHistoryPathHtml
1291 ).filter(Boolean),
1292 buildResultHref(item.pageId, item.tabs, item.anchor),
1293 item.linkText
11141294 )
11151295 window.dispatchEvent(
11161296 new CustomEvent('search-nav', {
@@ -1127,7 +1307,9 @@ function navigateToUrlResult(item: UrlResult) {
11271307
11281308onKeyStroke('Enter', (e) => {
11291309 if (e.isComposing) return
1130 if (e.target instanceof HTMLButtonElement && e.target.type !== 'submit') return
1310 if (e.target instanceof HTMLButtonElement && e.target.type !== 'submit') {
1311 return
1312 }
11311313
11321314 const index = selectedIndex.value - 1
11331315 if (index === -1) {
@@ -1144,12 +1326,21 @@ onKeyStroke('Enter', (e) => {
11441326 }
11451327
11461328 const selectedPackage = pagedResults.value[index]
1147 if (e.target instanceof HTMLInputElement && !selectedPackage) { e.preventDefault(); return }
1329 if (e.target instanceof HTMLInputElement && !selectedPackage) {
1330 e.preventDefault()
1331 return
1332 }
11481333 if (selectedPackage) {
11491334 saveToHistory(
1150 filterText.value, searchMode.value,
1151 [getPageLabel(getPageKey(String(selectedPackage.id)), pageMeta), ...selectedPackage.titles, selectedPackage.title].map(toHistoryPathHtml).filter(Boolean),
1152 getSearchResultHref(selectedPackage), selectedPackage.title
1335 filterText.value,
1336 searchMode.value,
1337 [
1338 getPageLabel(getPageKey(String(selectedPackage.id)), pageMeta),
1339 ...selectedPackage.titles,
1340 selectedPackage.title
1341 ].map(toHistoryPathHtml).filter(Boolean),
1342 getSearchResultHref(selectedPackage),
1343 selectedPackage.title
11531344 )
11541345 window.dispatchEvent(
11551346 new CustomEvent('search-nav', {
@@ -1167,9 +1358,15 @@ onKeyStroke('Enter', (e) => {
11671358
11681359function onResultClick(item: SearchResult & Result) {
11691360 saveToHistory(
1170 filterText.value, searchMode.value,
1171 [getPageLabel(getPageKey(String(item.id)), pageMeta), ...item.titles, item.title].map(toHistoryPathHtml).filter(Boolean),
1172 getSearchResultHref(item), item.title
1361 filterText.value,
1362 searchMode.value,
1363 [
1364 getPageLabel(getPageKey(String(item.id)), pageMeta),
1365 ...item.titles,
1366 item.title
1367 ].map(toHistoryPathHtml).filter(Boolean),
1368 getSearchResultHref(item),
1369 item.title
11731370 )
11741371 window.dispatchEvent(
11751372 new CustomEvent('search-nav', {
@@ -1184,7 +1381,10 @@ function onResultClick(item: SearchResult & Result) {
11841381}
11851382
11861383onKeyStroke('Escape', () => {
1187 if (showSettingsPopup.value) { showSettingsPopup.value = false; return }
1384 if (showSettingsPopup.value) {
1385 showSettingsPopup.value = false
1386 return
1387 }
11881388 showSearch.value = false
11891389})
11901390
@@ -1215,17 +1415,27 @@ const defaultTranslations: { modal: ModalTranslations } = {
12151415const translate = createSearchTranslate(defaultTranslations)
12161416
12171417// Back
1218onMounted(() => { window.history.pushState(null, '', null) })
1219useEventListener('popstate', (event) => { event.preventDefault(); showSearch.value = false })
1418onMounted(() => {
1419 window.history.pushState(null, '', null)
1420})
1421useEventListener('popstate', (event) => {
1422 event.preventDefault()
1423 showSearch.value = false
1424})
12201425
12211426// Lock body
12221427const isLocked = useScrollLock(inBrowser ? document.body : null)
12231428
12241429watch(() => showSearch.value, (val) => {
1225 if (!val) { isLocked.value = false; return }
1430 if (!val) {
1431 isLocked.value = false
1432 return
1433 }
12261434 nextTick(() => {
12271435 isLocked.value = true
1228 nextTick().then(() => { activate() })
1436 nextTick().then(() => {
1437 activate()
1438 })
12291439 })
12301440})
12311441
@@ -1352,16 +1562,21 @@ function onMouseMove(e: MouseEvent) {
13521562 item.anchor + '-' + index"
13531563 class="result-layout"
13541564 :id="'localsearch-item-' + (index + 1)"
1355 :aria-selected="selectedIndex === index + 1 ? 'true' : 'false'"
1565 :aria-selected="selectedIndex === index + 1
1566 ? 'true'
1567 : 'false'"
13561568 role="option"
13571569 v-bind="resultMotion(index)"
13581570 >
13591571 <div
13601572 class="result url-result-card"
1361 :class="{ selected: selectedIndex === index + 1 }"
1573 :class="{
1574 selected: selectedIndex === index + 1
1575 }"
13621576 :aria-label="item.href"
13631577 role="button"
1364 @mouseenter="!disableMouseOver && (selectedIndex = index + 1)"
1578 @mouseenter="!disableMouseOver &&
1579 (selectedIndex = index + 1)"
13651580 @focusin="selectedIndex = index + 1"
13661581 @click="navigateToUrlResult(item)"
13671582 :data-index="index + 1"
@@ -1369,16 +1584,29 @@ function onMouseMove(e: MouseEvent) {
13691584 <div class="url-result-body">
13701585 <div class="url-path">
13711586 <Hash
1372 v-if="item.anchor || item.titles.length > 0"
1587 v-if="item.anchor ||
1588 item.titles.length > 0"
13731589 stroke-width="2"
13741590 :size="18"
13751591 />
13761592 <File v-else stroke-width="2" :size="18" />
1377 <span v-for="(t, ti) in item.titles" :key="ti" class="url-path-segment">
1593 <span
1594 v-for="(t, ti) in item.titles"
1595 :key="ti"
1596 class="url-path-segment"
1597 >
13781598 <span class="text" v-html="t" />
1379 <ArrowRight stroke-width="2" :size="18" class="mx-0.5" />
1599 <ArrowRight
1600 stroke-width="2"
1601 :size="18"
1602 class="mx-0.5"
1603 />
13801604 </span>
1381 <span v-if="item.linkText" class="url-path-current" v-html="item.linkText" />
1605 <span
1606 v-if="item.linkText"
1607 class="url-path-current"
1608 v-html="item.linkText"
1609 />
13821610 </div>
13831611 <a
13841612 :href="item.href"
@@ -1401,42 +1629,62 @@ function onMouseMove(e: MouseEvent) {
14011629 <component
14021630 :is="searchMotionLi"
14031631 v-for="(p, index) in pagedResults"
1404 :key="'normal-' + normalCurrentPage + '-' + p.id + (p._linkIndex != null ? '-' + p._linkIndex : '')"
1632 :key="'normal-' + normalCurrentPage + '-' +
1633 p.id + (p._linkIndex != null
1634 ? '-' + p._linkIndex
1635 : '')"
14051636 class="result-layout"
14061637 :id="'localsearch-item-' + (index + 1)"
1407 :aria-selected="selectedIndex === index + 1 ? 'true' : 'false'"
1638 :aria-selected="selectedIndex === index + 1
1639 ? 'true'
1640 : 'false'"
14081641 role="option"
14091642 v-bind="resultMotion(index)"
14101643 >
14111644 <a
14121645 :href="getSearchResultHref(p)"
14131646 class="result"
1414 :class="{ selected: selectedIndex === index + 1 }"
1647 :class="{
1648 selected: selectedIndex === index + 1
1649 }"
14151650 :aria-label="[...p.titles, p.title].join(' > ')"
1416 @mouseenter="!disableMouseOver && (selectedIndex = index + 1)"
1651 @mouseenter="!disableMouseOver &&
1652 (selectedIndex = index + 1)"
14171653 @focusin="selectedIndex = index + 1"
14181654 @click="onResultClick(p)"
14191655 :data-index="index + 1"
1420 :data-link-title="p._linkIndex != null ? p.title : undefined"
1656 :data-link-title="p._linkIndex != null
1657 ? p.title
1658 : undefined"
14211659 >
14221660 <div>
14231661 <div class="titles">
14241662 <Hash
1425 v-if="getDocAnchor(p.id) || p.titles.length > 0"
1663 v-if="getDocAnchor(p.id) ||
1664 p.titles.length > 0"
14261665 stroke-width="2"
14271666 :size="18"
14281667 />
14291668 <File v-else stroke-width="2" :size="18" />
1430 <span v-for="(t, index) in p.titles" :key="index" class="title">
1669 <span
1670 v-for="(t, index) in p.titles"
1671 :key="index"
1672 class="title"
1673 >
14311674 <span class="text" v-html="t" />
1432 <ArrowRight stroke-width="2" :size="18" class="mx-0.5" />
1675 <ArrowRight
1676 stroke-width="2"
1677 :size="18"
1678 class="mx-0.5"
1679 />
14331680 </span>
14341681 <span class="title main">
14351682 <span class="text" v-html="p.title" />
14361683 </span>
14371684 </div>
14381685 <div
1439 v-if="showDetailedList && hasExcerptPreview(p.text)"
1686 v-if="showDetailedList &&
1687 hasExcerptPreview(p.text)"
14401688 class="excerpt-wrapper"
14411689 >
14421690 <component
@@ -1758,4 +2006,4 @@ svg {
17582006 text-decoration: underline;
17592007 text-underline-offset: 2px;
17602008}
1761</style>
\ No newline at end of file
2009</style>