Skip to content

Commit 9d9558a

Browse files
committed
fix(theme): ensure outline marker follows click
closes #3878
1 parent 99c0cec commit 9d9558a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/client/theme-default/composables/outline.ts

+17
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,12 @@ export function useActiveAnchor(
117117
const onScroll = throttleAndDebounce(setActiveLink, 100)
118118

119119
let prevActiveLink: HTMLAnchorElement | null = null
120+
let ignoreScrollOnce: boolean = false
120121

121122
onMounted(() => {
122123
requestAnimationFrame(setActiveLink)
123124
window.addEventListener('scroll', onScroll)
125+
container.value.addEventListener('click', onClick)
124126
})
125127

126128
onUpdated(() => {
@@ -130,13 +132,28 @@ export function useActiveAnchor(
130132

131133
onUnmounted(() => {
132134
window.removeEventListener('scroll', onScroll)
135+
container.value.removeEventListener('click', onClick)
133136
})
134137

138+
function onClick(e: MouseEvent) {
139+
if (!isAsideEnabled.value || !(e.target instanceof HTMLAnchorElement)) {
140+
return
141+
}
142+
143+
activateLink(location.hash)
144+
ignoreScrollOnce = true
145+
}
146+
135147
function setActiveLink() {
136148
if (!isAsideEnabled.value) {
137149
return
138150
}
139151

152+
if (ignoreScrollOnce) {
153+
ignoreScrollOnce = false
154+
return
155+
}
156+
140157
const scrollY = window.scrollY
141158
const innerHeight = window.innerHeight
142159
const offsetHeight = document.body.offsetHeight

0 commit comments

Comments
 (0)