The code relied on an IntersectionOberver, so the ToC was only updated when a heading was in the viewport.
It meant that if we jumped to a part of the text that has no heading, the ToC would still point to the old entry. This issue can be reproduced by clicking on a link to an endpoint definition, clicking somewhere in the scrollbar, or using the search function from the browser.
The new code looks for the correct heading when the view is scrolled so the correct entry is always selected.
The code relied on an
IntersectionOberver
, so the ToC was only updated when a heading was in the viewport. It meant that if we jumped to a part of the text that has no heading, the ToC would still point to the old entry. This issue can be reproduced by clicking on a link to an endpoint definition, clicking somewhere in the scrollbar, or using the search function from the browser.The new code looks for the correct heading when the view is scrolled so the correct entry is always selected.
Pull Request Checklist
Preview: https://pr1991--matrix-spec-previews.netlify.app