From d4f5b1377c21a54c862246efce77db601cf58bbd Mon Sep 17 00:00:00 2001 From: squidfunk Date: Tue, 18 Feb 2020 17:07:20 +0100 Subject: [PATCH] Fixed invalid anchor list offset for hidden anchors --- src/assets/javascripts/observables/anchor/index.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/assets/javascripts/observables/anchor/index.ts b/src/assets/javascripts/observables/anchor/index.ts index 33468a0e6..740240ed0 100644 --- a/src/assets/javascripts/observables/anchor/index.ts +++ b/src/assets/javascripts/observables/anchor/index.ts @@ -132,9 +132,18 @@ export function watchAnchorList( break } } + + /* If the current anchor is hidden, continue with its parent */ + let offset = target.offsetTop + while (!offset && target.parentElement) { + target = target.parentElement + offset = target.offsetTop + } + + /* Map reversed anchor path to vertical offset */ return index.set( reverse(path = [...path, anchor]), - target.offsetTop + offset ) }, new Map()) }),