Skip to content

Fix scroll sync clicking #359

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

Merged
merged 2 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion dist/tocbot.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -580,9 +580,11 @@ function init (customOptions) {
}

// Update Sidebar and bind listeners.
let isClick = false
_scrollListener = throttle((e) => {
_buildHtml.updateToc(_headingsArray)
!_options.disableTocScrollSync && (0,_update_toc_scroll_js__WEBPACK_IMPORTED_MODULE_4__["default"])(_options)
// Only do this update for normal scrolls and not during clicks.
!_options.disableTocScrollSync && !isClick && (0,_update_toc_scroll_js__WEBPACK_IMPORTED_MODULE_4__["default"])(_options)

if (_options.enableUrlHashUpdateOnScroll) {
const enableUpdatingHash = _buildHtml.getCurrentlyHighlighting()
Expand Down Expand Up @@ -618,6 +620,7 @@ function init (customOptions) {
// Bind click listeners to disable animation.
let timeout = null
clickListener = throttle((event) => {
isClick = true
if (_options.scrollSmooth) {
_buildHtml.disableTocAnimation(event)
}
Expand All @@ -627,6 +630,11 @@ function init (customOptions) {
timeout = setTimeout(() => {
_buildHtml.enableTocAnimation()
}, _options.scrollSmoothDuration)
// Set is click w/ a bit of delay so that animations can finish
// and we don't disturb the user while they click the toc.
setTimeout(() => {
isClick = false
}, _options.scrollSmoothDuration + 100)
}, _options.throttleTimeout)

if (
Expand Down
10 changes: 9 additions & 1 deletion dist/tocbot.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading