fix(theme): ensure outline marker follows click

closes #3878
pull/3879/head
Em Zhan 2 months ago
parent 99c0cece62
commit 9d9558a86a

@ -117,10 +117,12 @@ export function useActiveAnchor(
const onScroll = throttleAndDebounce(setActiveLink, 100)
let prevActiveLink: HTMLAnchorElement | null = null
let ignoreScrollOnce: boolean = false
onMounted(() => {
requestAnimationFrame(setActiveLink)
window.addEventListener('scroll', onScroll)
container.value.addEventListener('click', onClick)
})
onUpdated(() => {
@ -130,13 +132,28 @@ export function useActiveAnchor(
onUnmounted(() => {
window.removeEventListener('scroll', onScroll)
container.value.removeEventListener('click', onClick)
})
function onClick(e: MouseEvent) {
if (!isAsideEnabled.value || !(e.target instanceof HTMLAnchorElement)) {
return
}
activateLink(location.hash)
ignoreScrollOnce = true
}
function setActiveLink() {
if (!isAsideEnabled.value) {
return
}
if (ignoreScrollOnce) {
ignoreScrollOnce = false
return
}
const scrollY = window.scrollY
const innerHeight = window.innerHeight
const offsetHeight = document.body.offsetHeight

Loading…
Cancel
Save