From 0a6869dcb69683e1aeb8bf1bdc4bde1c762b8efa Mon Sep 17 00:00:00 2001 From: Benjamin Dobell Date: Thu, 11 Mar 2021 00:04:56 +1100 Subject: [PATCH] Support TOC anchor targets vertical order differing from TOC order. --- src/assets/javascripts/components/toc/index.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/assets/javascripts/components/toc/index.ts b/src/assets/javascripts/components/toc/index.ts index d7825146c..27a266f94 100644 --- a/src/assets/javascripts/components/toc/index.ts +++ b/src/assets/javascripts/components/toc/index.ts @@ -161,6 +161,13 @@ export function watchTableOfContents( }, new Map()) }), + /* Sort index by vertical offset */ + map(index => ( + new Map( + [...index].sort(([, offsetA], [, offsetB]) => offsetA - offsetB) + ) + )), + /* Re-compute partition when viewport offset changes */ switchMap(index => combineLatest([adjust$, viewport$]) .pipe(