mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +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:
parent
eb5dc01379
commit
1379bf3f15
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue