提交 907924ab 编写于 作者: M Matt Bierner

Reveal absolute top of markdown preview when scrolling to line 0

Fixes #61816
上级 fe63c7e2
......@@ -88,8 +88,19 @@ export function getLineElementsAtPageOffset(offset: number): { previous: CodeLin
* Attempt to reveal the element for a source line in the editor.
*/
export function scrollToRevealSourceLine(line: number) {
if (!getSettings().scrollPreviewWithEditor) {
return;
}
if (line <= 0) {
window.scroll(window.scrollX, 0);
return;
}
const { previous, next } = getElementsForSourceLine(line);
if (previous && getSettings().scrollPreviewWithEditor) {
if (!previous) {
return;
}
let scrollTo = 0;
const rect = previous.element.getBoundingClientRect();
const previousTop = rect.top;
......@@ -98,12 +109,10 @@ export function scrollToRevealSourceLine(line: number) {
const betweenProgress = (line - previous.line) / (next.line - previous.line);
const elementOffset = next.element.getBoundingClientRect().top - previousTop;
scrollTo = previousTop + betweenProgress * elementOffset;
}
else {
} else {
scrollTo = previousTop;
}
window.scroll(0, Math.max(1, window.scrollY + scrollTo));
}
window.scroll(window.scrollX, Math.max(1, window.scrollY + scrollTo));
}
export function getEditorLineNumberForPageOffset(offset: number) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册