Commit 1e50da773d

1e50da773d88c45cabd0cb33d95b66429265bb99

parent: ff8a0f5666

Unsigned

Duck <57977673+woducku@users.noreply.github.com> · 2026-07-28 17:18 UTC

commit

Layout: unified · split

docs/.vitepress/theme/Layout.vue +40 −1
@@ -73,6 +73,39 @@ if (!import.meta.env.SSR) {
7373 typeof event.detail?.resultText === 'string'
7474 ? event.detail.resultText
7575 : ''
76
77 const anchor = event instanceof CustomEvent &&
78 typeof event.detail?.anchor === 'string'
79 ? event.detail.anchor
80 : ''
81
82 if (anchor && anchor === window.location.hash.slice(1)) {
83 const target = getTargetByHash(anchor)
84 if (target) {
85 void nextTick(() => {
86 if (searchNavigated) {
87 highlightSearchResult(target)
88 resetSearchNavigation()
89 }
90 })
91 }
92 }
93
94 let attempts = 0
95 const retryHighlight = () => {
96 if (!searchNavigated) return
97 attempts++
98 const currentHash = window.location.hash.slice(1)
99 if (!currentHash) return
100 const target = getTargetByHash(currentHash)
101 if (target) {
102 highlightSearchResult(target)
103 resetSearchNavigation()
104 } else if (attempts < 15) {
105 requestAnimationFrame(retryHighlight)
106 }
107 }
108 requestAnimationFrame(retryHighlight)
76109 })
77110}
78111
@@ -192,7 +225,13 @@ const highlightSearchResult = (target?: HTMLElement) => {
192225 )
193226 highlightTabPath = panel ? getPanelTabPath(panel) : null
194227 highlightTerm = term
195 applyHighlightWithin(target, term)
228
229 if (!applyHighlightWithin(target, term)) {
230 const docRoot = document.querySelector<HTMLElement>('.VPDoc .vp-doc')
231 if (docRoot) {
232 applyHighlightWithin(docRoot, term)
233 }
234 }
196235}
197236
198237const reapplyHighlightIfNeeded = (panel: HTMLElement) => {
docs/.vitepress/theme/components/search/Search.vue +21 −3
@@ -1082,7 +1082,13 @@ function navigateToUrlResult(item: UrlResult) {
10821082 buildResultHref(item.pageId, item.tabs, item.anchor), item.linkText
10831083 )
10841084 window.dispatchEvent(
1085 new CustomEvent('search-nav', { detail: { query: filterText.value, resultText: item.linkText } })
1085 new CustomEvent('search-nav', {
1086 detail: {
1087 query: filterText.value,
1088 resultText: item.linkText,
1089 anchor: item.anchor
1090 }
1091 })
10861092 )
10871093 router.go(buildResultHref(item.pageId, item.tabs, item.anchor))
10881094 showSearch.value = false
@@ -1115,7 +1121,13 @@ onKeyStroke('Enter', (e) => {
11151121 getSearchResultHref(selectedPackage), selectedPackage.title
11161122 )
11171123 window.dispatchEvent(
1118 new CustomEvent('search-nav', { detail: { query: filterText.value, resultText: selectedPackage.title } })
1124 new CustomEvent('search-nav', {
1125 detail: {
1126 query: filterText.value,
1127 resultText: selectedPackage.title,
1128 anchor: getDocAnchor(String(selectedPackage.id))
1129 }
1130 })
11191131 )
11201132 router.go(getSearchResultHref(selectedPackage))
11211133 showSearch.value = false
@@ -1129,7 +1141,13 @@ function onResultClick(item: SearchResult & Result) {
11291141 getSearchResultHref(item), item.title
11301142 )
11311143 window.dispatchEvent(
1132 new CustomEvent('search-nav', { detail: { query: filterText.value, resultText: item.title } })
1144 new CustomEvent('search-nav', {
1145 detail: {
1146 query: filterText.value,
1147 resultText: item.title,
1148 anchor: getDocAnchor(String(item.id))
1149 }
1150 })
11331151 )
11341152 showSearch.value = false
11351153}