mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 20:26:08 +00:00
Fix markdown webview state updates (#178153)
Fixes #164071 Also fixes the webview not scrolling when the resources changes
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user