Commit e579b625b2

e579b625b2a45a7bf0bc45639bfb54b7851583d3

parent: a426266132

Unsigned

Duck <57977673+woducku@users.noreply.github.com> · 2026-06-09 13:13 UTC

search fixes for nested collapsible

Layout: unified · split

docs/.vitepress/configs/markdown/index.ts +4 −1
@@ -229,12 +229,15 @@ function injectSearchHeadings(src: string) {
229229 const [, indent, , title] = match
230230 const headingTitle = title.trim()
231231 if (!headingTitle) continue
232 const headingLevel = containerStack.includes('tabs') ? 4 : 3
232233
233234 lines.splice(
234235 i + 1,
235236 0,
236237 '',
237 `${indent}### ${headingTitle} {.collapsible-search-heading}`,
238 `${indent}${
239 '#'.repeat(headingLevel)
240 } ${headingTitle} {.collapsible-search-heading}`,
238241 ''
239242 )
240243 i += 3
docs/.vitepress/plugins/urlSearchPlugin.ts +7 −4
@@ -102,11 +102,14 @@ function extractLinksFromMarkdown(src: string, pageId: string): PageLink[] {
102102 nextLine++
103103 }
104104
105 // The markdown renderer injects a searchable H3 for collapsibles that
106 // don't already start with a heading. Mirror that anchor so URL search
107 // can deep-link into and auto-open those collapsibles.
105 // The markdown renderer injects searchable headings for collapsibles
106 // that don't already start with a heading. Mirror that anchor so URL
107 // search can deep-link into and auto-open those collapsibles.
108108 if (!/^#{1,6}\s+/.test(lines[nextLine]?.trim() ?? '')) {
109 setHeading(2, collapsibleMatch[2].trim())
109 setHeading(
110 containerStack.includes('tabs') ? 3 : 2,
111 collapsibleMatch[2].trim()
112 )
110113 }
111114 continue
112115 }
docs/.vitepress/theme/Layout.vue +16 −7
@@ -257,8 +257,14 @@ const selectTabContainingQuery = async (target: HTMLElement, query: string) => {
257257}
258258
259259const openCollapsibles = async (target: HTMLElement) => {
260 let scrollTarget = getScrollTargetForAnchor(target)
261 let el: HTMLElement | null = target
260 await selectTabContainingQuery(target, searchQuery)
261 await nextTick()
262 await nextFrame()
263
264 const hashTarget = getTargetByHash(window.location.hash.slice(1))
265 const activeTarget = hashTarget ?? target
266 let scrollTarget = getScrollTargetForAnchor(activeTarget)
267 let el: HTMLElement | null = activeTarget
262268
263269 while ((el = el.closest('details'))) {
264270 el.open = true
@@ -266,7 +272,7 @@ const openCollapsibles = async (target: HTMLElement) => {
266272 el = el.parentElement
267273 }
268274
269 const tagName = target.tagName
275 const tagName = activeTarget.tagName
270276 if (tagName.length === 2 && tagName[0] === 'H') {
271277 const level = +tagName[1]
272278 if (level >= 1 && level <= 6) {
@@ -277,7 +283,7 @@ const openCollapsibles = async (target: HTMLElement) => {
277283 return terms.every((term) => text.includes(term))
278284 }
279285
280 let sibling = target.nextElementSibling
286 let sibling = activeTarget.nextElementSibling
281287
282288 while (sibling) {
283289 const siblingTag = sibling.tagName
@@ -289,7 +295,9 @@ const openCollapsibles = async (target: HTMLElement) => {
289295 if (siblingTag === 'DETAILS') {
290296 if (detailsContainsTerms(sibling as HTMLElement)) {
291297 ;(sibling as HTMLDetailsElement).open = true
292 if (scrollTarget === target) scrollTarget = sibling as HTMLElement
298 if (scrollTarget === activeTarget) {
299 scrollTarget = sibling as HTMLElement
300 }
293301 }
294302 }
295303
@@ -297,7 +305,7 @@ const openCollapsibles = async (target: HTMLElement) => {
297305 for (let i = 0, len = nested.length; i < len; i++) {
298306 if (detailsContainsTerms(nested[i])) {
299307 nested[i].open = true
300 if (scrollTarget === target) scrollTarget = nested[i]
308 if (scrollTarget === activeTarget) scrollTarget = nested[i]
301309 }
302310 }
303311
@@ -306,7 +314,8 @@ const openCollapsibles = async (target: HTMLElement) => {
306314 }
307315 }
308316
309 await selectTabContainingQuery(target, searchQuery)
317 await nextTick()
318 await nextFrame()
310319
311320 scrollToElement(scrollTarget)
312321}