From 107d3ab28ceca3fedfee51b127992d249b7fceb3 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Fri, 18 Nov 2022 13:02:56 -0800 Subject: [PATCH] Fix markdown scrolling between elements being too jumpy (#166746) Fixes #165055 We need to consider the distance between the end of the previous element and start of the next element. Previously we were taking distance from start of the previous to start of the next --- .../markdown-language-features/preview-src/scroll-sync.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/extensions/markdown-language-features/preview-src/scroll-sync.ts b/extensions/markdown-language-features/preview-src/scroll-sync.ts index e9fc98a269b..fe79470f329 100644 --- a/extensions/markdown-language-features/preview-src/scroll-sync.ts +++ b/extensions/markdown-language-features/preview-src/scroll-sync.ts @@ -133,8 +133,9 @@ export function scrollToRevealSourceLine(line: number, documentVersion: number, if (next && next.line !== previous.line) { // Between two elements. Go to percentage offset between them. const betweenProgress = (line - previous.line) / (next.line - previous.line); - const elementOffset = next.element.getBoundingClientRect().top - previousTop; - scrollTo = previousTop + betweenProgress * elementOffset; + const previousEnd = previousTop + rect.height; + const betweenHeight = next.element.getBoundingClientRect().top - previousEnd; + scrollTo = previousEnd + betweenProgress * betweenHeight; } else { const progressInElement = line - Math.floor(line); scrollTo = previousTop + (rect.height * progressInElement);