Fix markdown webview state updates (#178153)

Fixes #164071

Also fixes the webview not scrolling when the resources changes
This commit is contained in:
Matt Bierner 2023-03-23 10:51:09 -07:00 committed by GitHub
parent eb5dc01379
commit 1379bf3f15
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -23,14 +23,13 @@ let documentResource = settings.settings.source;
const vscode = acquireVsCodeApi();
const originalState = vscode.getState() ?? {} as any;
const state = {
originalState,
...originalState,
...getData<any>('data-state')
};
if (originalState?.resource !== state.resource) {
state.scrollProgress = undefined;
if (typeof originalState.scrollProgress !== 'undefined' && originalState?.resource !== state.resource) {
state.scrollProgress = 0;
}
// Make sure to sync VS Code state here
@ -67,7 +66,9 @@ onceDocumentLoaded(() => {
if (typeof scrollProgress === 'number' && !settings.settings.fragment) {
doAfterImagesLoaded(() => {
scrollDisabledCount += 1;
window.scrollTo(0, scrollProgress * document.body.clientHeight);
// Always set scroll of at least 1 to prevent VS Code's webview code from auto scrolling us
const scrollToY = Math.max(1, scrollProgress * document.body.clientHeight);
window.scrollTo(0, scrollToY);
});
return;
}