From 031bb964fc7252b44577854636f5f42c8a4669c4 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Thu, 18 Jun 2020 08:44:35 +0200 Subject: [PATCH] editors - call setEditorVisible before removing editor from DOM and thus remove onWillHide() method (fix #100271) --- src/vs/workbench/browser/composite.ts | 5 ----- .../browser/parts/editor/baseEditor.ts | 5 ----- .../browser/parts/editor/editorControl.ts | 13 +++++++------ .../contrib/notebook/browser/notebookEditor.ts | 17 ++++++++--------- 4 files changed, 15 insertions(+), 25 deletions(-) diff --git a/src/vs/workbench/browser/composite.ts b/src/vs/workbench/browser/composite.ts index 28f0c6bbfb5..afda9848e3c 100644 --- a/src/vs/workbench/browser/composite.ts +++ b/src/vs/workbench/browser/composite.ts @@ -33,9 +33,6 @@ export abstract class Composite extends Component implements IComposite { private readonly _onTitleAreaUpdate = this._register(new Emitter()); readonly onTitleAreaUpdate = this._onTitleAreaUpdate.event; - private readonly _onDidChangeVisibility = this._register(new Emitter()); - readonly onDidChangeVisibility = this._onDidChangeVisibility.event; - private _onDidFocus: Emitter | undefined; get onDidFocus(): Event { if (!this._onDidFocus) { @@ -135,8 +132,6 @@ export abstract class Composite extends Component implements IComposite { setVisible(visible: boolean): void { if (this.visible !== !!visible) { this.visible = visible; - - this._onDidChangeVisibility.fire(visible); } } diff --git a/src/vs/workbench/browser/parts/editor/baseEditor.ts b/src/vs/workbench/browser/parts/editor/baseEditor.ts index d9c992696e8..8fb47fe057b 100644 --- a/src/vs/workbench/browser/parts/editor/baseEditor.ts +++ b/src/vs/workbench/browser/parts/editor/baseEditor.ts @@ -137,11 +137,6 @@ export abstract class BaseEditor extends Composite implements IEditorPane { this._group = group; } - /** - * Called before the editor is being removed from the DOM. - */ - onWillHide() { } - protected getEditorMemento(editorGroupService: IEditorGroupsService, key: string, limit: number = 10): IEditorMemento { const mementoKey = `${this.getId()}${key}`; diff --git a/src/vs/workbench/browser/parts/editor/editorControl.ts b/src/vs/workbench/browser/parts/editor/editorControl.ts index f69053f693d..b3a49e5d197 100644 --- a/src/vs/workbench/browser/parts/editor/editorControl.ts +++ b/src/vs/workbench/browser/parts/editor/editorControl.ts @@ -198,18 +198,19 @@ export class EditorControl extends Disposable { // Stop any running operation this.editorOperation.stop(); - // Remove editor pane from parent and hide + // Indicate to editor pane before removing the editor from + // the DOM to give a chance to persist certain state that + // might depend on still being the active DOM element. + this._activeEditorPane.clearInput(); + this._activeEditorPane.setVisible(false, this.groupView); + + // Remove editor pane from parent const editorPaneContainer = this._activeEditorPane.getContainer(); if (editorPaneContainer) { - this._activeEditorPane.onWillHide(); this.parent.removeChild(editorPaneContainer); hide(editorPaneContainer); } - // Indicate to editor pane - this._activeEditorPane.clearInput(); - this._activeEditorPane.setVisible(false, this.groupView); - // Clear active editor pane this.doSetActiveEditorPane(null); } diff --git a/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts b/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts index e58a82d679d..f38670350e2 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts @@ -97,18 +97,17 @@ export class NotebookEditor extends BaseEditor { return this._widget.value; } - onWillHide() { - this._saveEditorViewState(this.input); - if (this.input && this._widget.value) { - // the widget is not transfered to other editor inputs - this._widget.value.onWillHide(); - } - super.onWillHide(); - } - setEditorVisible(visible: boolean, group: IEditorGroup | undefined): void { super.setEditorVisible(visible, group); this._groupListener.value = group?.onWillCloseEditor(e => this._saveEditorViewState(e.editor)); + + if (!visible) { + this._saveEditorViewState(this.input); + if (this.input && this._widget.value) { + // the widget is not transfered to other editor inputs + this._widget.value.onWillHide(); + } + } } focus() {