Skip to content

Commit 4e5715a

Browse files
committed
fix: anchor scroll positioning & TOC highlighting bugs
1 parent 678fe08 commit 4e5715a

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

docs/ui/src/js/02-on-this-page.js

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060

6161
function onScroll () {
6262
var scrolledBy = window.pageYOffset
63-
var buffer = getNumericStyleVal(document.documentElement, 'fontSize') * 1.15
6463
var ceil = article.offsetTop
6564
if (scrolledBy && window.innerHeight + scrolledBy + 2 >= document.documentElement.scrollHeight) {
6665
lastActiveFragment = Array.isArray(lastActiveFragment) ? lastActiveFragment : Array(lastActiveFragment || 0)
@@ -85,23 +84,11 @@
8584
})
8685
lastActiveFragment = undefined
8786
}
88-
var activeFragment
89-
headings.some(function (heading) {
90-
if (heading.getBoundingClientRect().top + getNumericStyleVal(heading, 'paddingTop') - buffer > ceil) return true
91-
activeFragment = '#' + heading.id
92-
})
93-
if (activeFragment) {
94-
if (activeFragment === lastActiveFragment) return
95-
if (lastActiveFragment) links[lastActiveFragment].classList.remove('is-active')
96-
var activeLink = links[activeFragment]
97-
activeLink.classList.add('is-active')
98-
if (list.scrollHeight > list.offsetHeight) {
99-
list.scrollTop = Math.max(0, activeLink.offsetTop + activeLink.offsetHeight - list.offsetHeight)
100-
}
101-
lastActiveFragment = activeFragment
102-
} else if (lastActiveFragment) {
103-
links[lastActiveFragment].classList.remove('is-active')
104-
lastActiveFragment = undefined
87+
// Scroll-based highlighting disabled - fragment jumper handles TOC highlighting
88+
// Only keep the TOC scrolling functionality for auto-scroll to active item
89+
var activeLink = document.querySelector('aside.toc a.is-active')
90+
if (activeLink && list.scrollHeight > list.offsetHeight) {
91+
list.scrollTop = Math.max(0, activeLink.offsetTop + activeLink.offsetHeight - list.offsetHeight)
10592
}
10693
}
10794

docs/ui/src/js/03-fragment-jumper.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,22 @@
2525
var y = elementTop - toolbarHeight
2626
var instant = e === false && supportsScrollToOptions
2727
instant ? window.scrollTo({ left: 0, top: y, behavior: 'instant' }) : window.scrollTo(0, y)
28+
29+
updateTocHighlighting('#' + this.id)
30+
}
31+
32+
function updateTocHighlighting (targetFragment) {
33+
var tocLinks = document.querySelectorAll('aside.toc a[href^="#"]')
34+
if (tocLinks.length === 0) return
35+
36+
tocLinks.forEach(function (link) {
37+
link.classList.remove('is-active')
38+
})
39+
40+
var targetLink = document.querySelector('aside.toc a[href="' + targetFragment + '"]')
41+
if (targetLink) {
42+
targetLink.classList.add('is-active')
43+
}
2844
}
2945

3046
window.addEventListener('load', function jumpOnLoad (e) {

0 commit comments

Comments
 (0)