Skip to content

Commit 54543cf

Browse files
Fix: New md file scrolls to Top. (microsoft#164999)
Fixes microsoft#164071.
1 parent 78f6c8c commit 54543cf

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

extensions/markdown-language-features/preview-src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ function doAfterImagesLoaded(cb: () => void) {
5757
}
5858

5959
onceDocumentLoaded(() => {
60-
const scrollProgress = state.scrollProgress;
60+
const scrollTo = !isNaN(state.line) ? state.line : state.scrollProgress;
6161

62-
if (typeof scrollProgress === 'number' && !settings.settings.fragment) {
62+
if (typeof scrollTo === 'number' && !settings.settings.fragment) {
6363
doAfterImagesLoaded(() => {
6464
scrollDisabledCount += 1;
65-
window.scrollTo(0, scrollProgress * document.body.clientHeight);
65+
window.scrollTo(0, scrollTo * document.body.clientHeight);
6666
});
6767
return;
6868
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,8 @@ export class DynamicMarkdownPreview extends Disposable implements IManagedMarkdo
755755
default:
756756
return;
757757
}
758+
} else if (!scrollLocation) {
759+
scrollLocation = new StartingScrollLine(0);
758760
}
759761

760762
this._preview.dispose();

0 commit comments

Comments
 (0)