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) {
73 typeof event.detail?.resultText === 'string' 73 typeof event.detail?.resultText === 'string'
74 ? event.detail.resultText 74 ? event.detail.resultText
75 : '' 75 : ''
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)
76 }) 109 })
77} 110}
78 111
@@ -192,7 +225,13 @@ const highlightSearchResult = (target?: HTMLElement) => {
192 ) 225 )
193 highlightTabPath = panel ? getPanelTabPath(panel) : null 226 highlightTabPath = panel ? getPanelTabPath(panel) : null
194 highlightTerm = term 227 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 }
196} 235}
197 236
198const reapplyHighlightIfNeeded = (panel: HTMLElement) => { 237const reapplyHighlightIfNeeded = (panel: HTMLElement) => {
docs/.vitepress/theme/components/search/Search.vue +21 −3
@@ -1082,7 +1082,13 @@ function navigateToUrlResult(item: UrlResult) {
1082 buildResultHref(item.pageId, item.tabs, item.anchor), item.linkText 1082 buildResultHref(item.pageId, item.tabs, item.anchor), item.linkText
1083 ) 1083 )
1084 window.dispatchEvent( 1084 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 })
1086 ) 1092 )
1087 router.go(buildResultHref(item.pageId, item.tabs, item.anchor)) 1093 router.go(buildResultHref(item.pageId, item.tabs, item.anchor))
1088 showSearch.value = false 1094 showSearch.value = false
@@ -1115,7 +1121,13 @@ onKeyStroke('Enter', (e) => {
1115 getSearchResultHref(selectedPackage), selectedPackage.title 1121 getSearchResultHref(selectedPackage), selectedPackage.title
1116 ) 1122 )
1117 window.dispatchEvent( 1123 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 })
1119 ) 1131 )
1120 router.go(getSearchResultHref(selectedPackage)) 1132 router.go(getSearchResultHref(selectedPackage))
1121 showSearch.value = false 1133 showSearch.value = false
@@ -1129,7 +1141,13 @@ function onResultClick(item: SearchResult & Result) {
1129 getSearchResultHref(item), item.title 1141 getSearchResultHref(item), item.title
1130 ) 1142 )
1131 window.dispatchEvent( 1143 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 })
1133 ) 1151 )
1134 showSearch.value = false 1152 showSearch.value = false
1135} 1153}