Skip to content
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

Improve the JS script to highlight the current ToC entry #1991

Merged
merged 4 commits into from
Nov 12, 2024

Conversation

zecakeh
Copy link
Contributor

@zecakeh zecakeh commented Nov 7, 2024

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

The ToC is now generated by Hugo.

Signed-off-by: Kévin Commaille <[email protected]>
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.

The new code looks for the correct heading when the view is scrolled so the correct entry is always selected.

Signed-off-by: Kévin Commaille <[email protected]>
@zecakeh zecakeh requested a review from a team as a code owner November 7, 2024 16:35
Signed-off-by: Kévin Commaille <[email protected]>
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks!

layouts/partials/hooks/body-end.html Outdated Show resolved Hide resolved
@richvdh richvdh enabled auto-merge (squash) November 12, 2024 22:53
@richvdh richvdh merged commit b1f66d1 into matrix-org:main Nov 12, 2024
12 checks passed
@zecakeh zecakeh deleted the toc branch November 13, 2024 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants