| @@ -257,8 +257,14 @@ const selectTabContainingQuery = async (target: HTMLElement, query: string) => { |
| 257 | } |
257 | } |
| 258 | |
258 | |
| 259 | const openCollapsibles = async (target: HTMLElement) => { |
259 | const openCollapsibles = async (target: HTMLElement) => { |
| 260 | let scrollTarget = getScrollTargetForAnchor(target) |
260 | await selectTabContainingQuery(target, searchQuery) |
| 261 | let el: HTMLElement | null = target |
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 |
| 262 | |
268 | |
| 263 | while ((el = el.closest('details'))) { |
269 | while ((el = el.closest('details'))) { |
| 264 | el.open = true |
270 | el.open = true |
| @@ -266,7 +272,7 @@ const openCollapsibles = async (target: HTMLElement) => { |
| 266 | el = el.parentElement |
272 | el = el.parentElement |
| 267 | } |
273 | } |
| 268 | |
274 | |
| 269 | const tagName = target.tagName |
275 | const tagName = activeTarget.tagName |
| 270 | if (tagName.length === 2 && tagName[0] === 'H') { |
276 | if (tagName.length === 2 && tagName[0] === 'H') { |
| 271 | const level = +tagName[1] |
277 | const level = +tagName[1] |
| 272 | if (level >= 1 && level <= 6) { |
278 | if (level >= 1 && level <= 6) { |
| @@ -277,7 +283,7 @@ const openCollapsibles = async (target: HTMLElement) => { |
| 277 | return terms.every((term) => text.includes(term)) |
283 | return terms.every((term) => text.includes(term)) |
| 278 | } |
284 | } |
| 279 | |
285 | |
| 280 | let sibling = target.nextElementSibling |
286 | let sibling = activeTarget.nextElementSibling |
| 281 | |
287 | |
| 282 | while (sibling) { |
288 | while (sibling) { |
| 283 | const siblingTag = sibling.tagName |
289 | const siblingTag = sibling.tagName |
| @@ -289,7 +295,9 @@ const openCollapsibles = async (target: HTMLElement) => { |
| 289 | if (siblingTag === 'DETAILS') { |
295 | if (siblingTag === 'DETAILS') { |
| 290 | if (detailsContainsTerms(sibling as HTMLElement)) { |
296 | if (detailsContainsTerms(sibling as HTMLElement)) { |
| 291 | ;(sibling as HTMLDetailsElement).open = true |
297 | ;(sibling as HTMLDetailsElement).open = true |
| 292 | if (scrollTarget === target) scrollTarget = sibling as HTMLElement |
298 | if (scrollTarget === activeTarget) { |
| |
299 | scrollTarget = sibling as HTMLElement |
| |
300 | } |
| 293 | } |
301 | } |
| 294 | } |
302 | } |
| 295 | |
303 | |
| @@ -297,7 +305,7 @@ const openCollapsibles = async (target: HTMLElement) => { |
| 297 | for (let i = 0, len = nested.length; i < len; i++) { |
305 | for (let i = 0, len = nested.length; i < len; i++) { |
| 298 | if (detailsContainsTerms(nested[i])) { |
306 | if (detailsContainsTerms(nested[i])) { |
| 299 | nested[i].open = true |
307 | nested[i].open = true |
| 300 | if (scrollTarget === target) scrollTarget = nested[i] |
308 | if (scrollTarget === activeTarget) scrollTarget = nested[i] |
| 301 | } |
309 | } |
| 302 | } |
310 | } |
| 303 | |
311 | |
| @@ -306,7 +314,8 @@ const openCollapsibles = async (target: HTMLElement) => { |
| 306 | } |
314 | } |
| 307 | } |
315 | } |
| 308 | |
316 | |
| 309 | await selectTabContainingQuery(target, searchQuery) |
317 | await nextTick() |
| |
318 | await nextFrame() |
| 310 | |
319 | |
| 311 | scrollToElement(scrollTarget) |
320 | scrollToElement(scrollTarget) |
| 312 | } |
321 | } |