-
Notifications
You must be signed in to change notification settings - Fork 447
Stable calculation of active toc #1456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
IntersectionObserver only notifies changed intersections. We need to track which heading tag currently intersects with viewport. Use the top-most intersecting heading to make user-clicked toc links match with active toc links.
|
🚀 Preview deployment available at: https://9a80f375.rdoc-6cd.pages.dev (commit: 5b079b8) |
st0012
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
kou
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
| return intersectingHeadings.has(heading); | ||
| }); | ||
| if (!firstIntersectingHeading) return; | ||
| var correspondingLink = document.querySelector('.toc-link[data-target="' + firstIntersectingHeading.id + '"]'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be simpler:
| var correspondingLink = document.querySelector('.toc-link[data-target="' + firstIntersectingHeading.id + '"]'); | |
| var correspondingLink = document.querySelector(`.toc-link[data-target="${firstIntersectingHeading.id}"]`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to keep it for now.
Currently this file doesn't use ES6 feature: const let ()=>{} and `${}`
I think we can use newer syntaxes, but I think it's better to do it in a separate pull request.
Remove assignment to unused variable Co-authored-by: Sutou Kouhei <kou@cozmixng.org>
Fix this unstable active table-of-contents link calculation shown in this video:
Clicking "Plugin types", active toc link will be "Option Parsing" or "File Parsing", depend on previous scroll position.
https://github.com/user-attachments/assets/bfd5c92a-9f11-4c9b-9267-86ae55607541
IntersectionObserver only notifies changed intersections.
We need to track which heading tag currently intersects with viewport. (I use Set in this pull request)
Use the top-most intersecting heading to make user-clicked toc links match with active toc links.