File tree Expand file tree Collapse file tree
apps/docs/src/components/override-components/TableOfContents Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -48,15 +48,16 @@ export class StarlightTOC extends HTMLElement {
4848 ) : HTMLHeadingElement | null => {
4949 if ( ! el ) return null ;
5050 const origin = el ;
51- while ( el ) {
52- if ( isHeading ( el ) ) return el ;
53- // Assign the previous sibling’s last, most deeply nested child to el.
54- el = el . previousElementSibling ;
55- while ( el ?. lastElementChild ) {
56- el = el . lastElementChild ;
51+ let current : Element | null = el ;
52+ while ( current ) {
53+ if ( isHeading ( current ) ) return current ;
54+ // Assign the previous sibling’s last, most deeply nested child to current.
55+ current = current . previousElementSibling ;
56+ while ( current ?. lastElementChild ) {
57+ current = current . lastElementChild ;
5758 }
5859 // Look for headings amongst siblings.
59- const h = getElementHeading ( el ) ;
60+ const h = getElementHeading ( current ) ;
6061 if ( h ) return h ;
6162 }
6263 // Walk back up the parent.
You can’t perform that action at this time.
0 commit comments