Make sure webview editor has not been disposed before claiming webview
Fixes #115743 Also added an exception to make sure we don't call `show` on a disposed of webview editor overlay
This commit is contained in:
parent
0568d26fad
commit
2e1166cb0c
2 changed files with 11 additions and 1 deletions
|
@ -60,10 +60,13 @@ export class DynamicWebviewEditorOverlay extends Disposable implements WebviewOv
|
|||
return !!this._webview.value?.isFocused;
|
||||
}
|
||||
|
||||
private _isDisposed = false;
|
||||
|
||||
private readonly _onDidDispose = this._register(new Emitter<void>());
|
||||
public onDidDispose = this._onDidDispose.event;
|
||||
|
||||
dispose() {
|
||||
this._isDisposed = true;
|
||||
this.container.remove();
|
||||
this._onDidDispose.fire();
|
||||
super.dispose();
|
||||
|
@ -138,6 +141,10 @@ export class DynamicWebviewEditorOverlay extends Disposable implements WebviewOv
|
|||
}
|
||||
|
||||
private show() {
|
||||
if (this._isDisposed) {
|
||||
throw new Error('Webview overlay is disposed');
|
||||
}
|
||||
|
||||
if (!this._webview.value) {
|
||||
const webview = this._webviewService.createWebviewElement(this.id, this._options, this._contentOptions, this.extension);
|
||||
this._webview.value = webview;
|
||||
|
|
|
@ -31,6 +31,7 @@ export class WebviewEditor extends EditorPane {
|
|||
private _element?: HTMLElement;
|
||||
private _dimension?: DOM.Dimension;
|
||||
private _visible = false;
|
||||
private _isDisposed = false;
|
||||
|
||||
private readonly _webviewVisibleDisposables = this._register(new DisposableStore());
|
||||
private readonly _onFocusWindowHandler = this._register(new MutableDisposable());
|
||||
|
@ -71,6 +72,8 @@ export class WebviewEditor extends EditorPane {
|
|||
}
|
||||
|
||||
public dispose(): void {
|
||||
this._isDisposed = true;
|
||||
|
||||
if (this._element) {
|
||||
this._element.remove();
|
||||
this._element = undefined;
|
||||
|
@ -133,7 +136,7 @@ export class WebviewEditor extends EditorPane {
|
|||
await super.setInput(input, options, context, token);
|
||||
await input.resolve();
|
||||
|
||||
if (token.isCancellationRequested) {
|
||||
if (token.isCancellationRequested || this._isDisposed) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue