Skip to content

Commit 107d3ab

Browse files
authored
Fix markdown scrolling between elements being too jumpy (microsoft#166746)
Fixes microsoft#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
1 parent ce40578 commit 107d3ab

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

extensions/markdown-language-features/preview-src/scroll-sync.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,9 @@ export function scrollToRevealSourceLine(line: number, documentVersion: number,
133133
if (next && next.line !== previous.line) {
134134
// Between two elements. Go to percentage offset between them.
135135
const betweenProgress = (line - previous.line) / (next.line - previous.line);
136-
const elementOffset = next.element.getBoundingClientRect().top - previousTop;
137-
scrollTo = previousTop + betweenProgress * elementOffset;
136+
const previousEnd = previousTop + rect.height;
137+
const betweenHeight = next.element.getBoundingClientRect().top - previousEnd;
138+
scrollTo = previousEnd + betweenProgress * betweenHeight;
138139
} else {
139140
const progressInElement = line - Math.floor(line);
140141
scrollTo = previousTop + (rect.height * progressInElement);

0 commit comments

Comments
 (0)