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
This commit is contained in:
Matt Bierner
2022-11-18 13:02:56 -08:00
committed by GitHub
parent ce405787ac
commit 107d3ab28c

View File

@@ -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);