tscanlin / tocbot

Build a table of contents from headings in an HTML document.
MIT License
1.39k stars 115 forks source link

Feature Request: optionally let TocScrollSync only enabled when the active header is not shown #323

Closed ibarapascal closed 9 months ago

ibarapascal commented 9 months ago

Currently, the TocScrollSync works like a charm.

However, if we have both the content and the Toc quite long as well as they are both scrollable, for example, when in the middle of an article, we scroll the Toc back to the top, then scroll in the same direction again (now scrolling the content), it jumps back to the near header's position due to the sync, which causes a flash on the Toc part.

I believe I could handle disabling the scroll of the content when the mouse is in Toc by myself.

In addition, Is it possible to add an option to enable the TocScrollSync only if the current header is not shown on the screen / overflowed? Maybe with some features like if not shown, move minimum steps to scroll it in, etc.

tscanlin commented 9 months ago

Thanks for suggesting! It seems like a good idea to me! Would you be willing to work on a PR for this?

tscanlin commented 9 months ago

Here is a PR with a proposed change that should accomplish what you want. Is this what you had in mind? https://github.com/tscanlin/tocbot/pull/325

ibarapascal commented 9 months ago

@tscanlin Thanks! Seems would be a good fit!
I'm not sure how it would affect other ones' using it since I'm not looking closely enough, I believe it is your decision-making, and I'm more than happy to use it, thanks again for your efforts.

tscanlin commented 9 months ago

Thanks for the suggestion!! And also thanks for the donation!!! 🙌 I think the behavior you described is a better user experience and didn't require adding very much code so it should be ok. This is published in the latest release. 4.25.0

Hope the end of the year treats you well! Thanks again! :)