diff --git a/extensions/markdown-language-features/src/features/preview.ts b/extensions/markdown-language-features/src/features/preview.ts index 8a357a2ff68..37a21b493fa 100644 --- a/extensions/markdown-language-features/src/features/preview.ts +++ b/extensions/markdown-language-features/src/features/preview.ts @@ -28,6 +28,8 @@ export class MarkdownPreview { private currentVersion?: { resource: vscode.Uri, version: number }; private forceUpdate = false; private isScrolling = false; + private _disposed: boolean = false; + public static async revive( webview: vscode.Webview, @@ -141,7 +143,7 @@ export class MarkdownPreview { vscode.window.onDidChangeTextEditorSelection(event => { if (this.isPreviewOf(event.textEditor.document.uri)) { - this.webview.postMessage({ + this.postMessage({ type: 'onDidChangeTextEditorSelection', line: event.selections[0].active.line, source: this.resource.toString() @@ -169,6 +171,11 @@ export class MarkdownPreview { } public dispose() { + if (this._disposed) { + return; + } + + this._disposed = true; this._onDisposeEmitter.fire(); this._onDisposeEmitter.dispose(); @@ -276,7 +283,7 @@ export class MarkdownPreview { if (typeof topLine === 'number') { this.logger.log('updateForView', { markdownFile: resource }); this.line = topLine; - this.webview.postMessage({ + this.postMessage({ type: 'updateView', line: topLine, source: resource.toString() @@ -284,6 +291,12 @@ export class MarkdownPreview { } } + private postMessage(msg: any) { + if (!this._disposed) { + this.webview.postMessage(msg); + } + } + private async doUpdate(): Promise { const resource = this._resource;