From 2e636ded90fd03c8fbcd0553f550325c01cbcc60 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Sun, 21 Nov 2021 14:04:28 +0100 Subject: [PATCH] editors - `clearInput` before `setInput` (#34697) --- src/vs/workbench/browser/parts/editor/editor.ts | 3 ++- .../browser/parts/editor/editorGroupView.ts | 2 +- .../workbench/browser/parts/editor/editorPane.ts | 3 ++- .../browser/parts/editor/editorPanes.ts | 16 +++++++++++++--- .../browser/parts/editor/editorWithViewState.ts | 10 ---------- .../workbench/browser/workbench.contribution.ts | 5 +++++ src/vs/workbench/common/editor.ts | 3 ++- .../contrib/notebook/browser/notebookEditor.ts | 2 -- .../walkThrough/browser/walkThroughPart.ts | 4 ---- 9 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/vs/workbench/browser/parts/editor/editor.ts b/src/vs/workbench/browser/parts/editor/editor.ts index 22791e7c00f..1d41297143c 100644 --- a/src/vs/workbench/browser/parts/editor/editor.ts +++ b/src/vs/workbench/browser/parts/editor/editor.ts @@ -39,7 +39,8 @@ export const DEFAULT_EDITOR_PART_OPTIONS: IEditorPartOptions = { closeEmptyGroups: true, labelFormat: 'default', splitSizing: 'distribute', - splitOnDragAndDrop: true + splitOnDragAndDrop: true, + experimentalDisableClearInputOnSetInput: false //TODO@bpasero remove this setting in December }; export function impactsEditorPartOptions(event: IConfigurationChangeEvent): boolean { diff --git a/src/vs/workbench/browser/parts/editor/editorGroupView.ts b/src/vs/workbench/browser/parts/editor/editorGroupView.ts index 6b54f1c7577..7a2aa70b8ac 100644 --- a/src/vs/workbench/browser/parts/editor/editorGroupView.ts +++ b/src/vs/workbench/browser/parts/editor/editorGroupView.ts @@ -211,7 +211,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView { this.element.appendChild(this.editorContainer); // Editor pane - this.editorPane = this._register(this.scopedInstantiationService.createInstance(EditorPanes, this.editorContainer, this)); + this.editorPane = this._register(this.scopedInstantiationService.createInstance(EditorPanes, this.editorContainer, this.accessor, this)); this._onDidChange.input = this.editorPane.onDidChangeSizeConstraints; // Track Focus diff --git a/src/vs/workbench/browser/parts/editor/editorPane.ts b/src/vs/workbench/browser/parts/editor/editorPane.ts index 23e36f6c84e..f87a7651c19 100644 --- a/src/vs/workbench/browser/parts/editor/editorPane.ts +++ b/src/vs/workbench/browser/parts/editor/editorPane.ts @@ -122,7 +122,8 @@ export abstract class EditorPane extends Composite implements IEditorPane { * resources associated with the input should be freed. * * This method can be called based on different contexts, e.g. when opening - * a different editor control or when closing all editors in a group. + * a different input or different editor control or when closing all editors + * in a group. * * To monitor the lifecycle of editor inputs, you should not rely on this * method, rather refer to the listeners on `IEditorGroup` via `IEditorGroupService`. diff --git a/src/vs/workbench/browser/parts/editor/editorPanes.ts b/src/vs/workbench/browser/parts/editor/editorPanes.ts index 86562c72954..d12911518bb 100644 --- a/src/vs/workbench/browser/parts/editor/editorPanes.ts +++ b/src/vs/workbench/browser/parts/editor/editorPanes.ts @@ -13,7 +13,7 @@ import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/la import { EditorPane } from 'vs/workbench/browser/parts/editor/editorPane'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IEditorProgressService, LongRunningOperation } from 'vs/platform/progress/common/progress'; -import { IEditorGroupView, DEFAULT_EDITOR_MIN_DIMENSIONS, DEFAULT_EDITOR_MAX_DIMENSIONS } from 'vs/workbench/browser/parts/editor/editor'; +import { IEditorGroupView, DEFAULT_EDITOR_MIN_DIMENSIONS, DEFAULT_EDITOR_MAX_DIMENSIONS, IEditorGroupsAccessor } from 'vs/workbench/browser/parts/editor/editor'; import { Emitter } from 'vs/base/common/event'; import { assertIsDefined } from 'vs/base/common/types'; import { IWorkspaceTrustManagementService } from 'vs/platform/workspace/common/workspaceTrust'; @@ -84,6 +84,7 @@ export class EditorPanes extends Disposable { constructor( private parent: HTMLElement, + private accessor: IEditorGroupsAccessor, private groupView: IEditorGroupView, @IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService, @IInstantiationService private readonly instantiationService: IInstantiationService, @@ -268,9 +269,18 @@ export class EditorPanes extends Disposable { // started will cancel the previous one. const operation = this.editorOperation.start(this.layoutService.isRestored() ? 800 : 3200); - // Set the input to the editor pane let cancelled = false; try { + + // Clear the current input before setting new input + // This ensures that a slow loading input will not + // be visible for the duration of the new input to + // load (https://github.com/microsoft/vscode/issues/34697) + if (this.accessor.partOptions.experimentalDisableClearInputOnSetInput !== true) { + editorPane.clearInput(); + } + + // Set the input to the editor pane await editorPane.setInput(editor, options, context, operation.token); if (!operation.isCurrent()) { @@ -309,7 +319,7 @@ export class EditorPanes extends Disposable { } closeEditor(editor: EditorInput): void { - if (this._activeEditorPane && this._activeEditorPane.input && editor.matches(this._activeEditorPane.input)) { + if (this._activeEditorPane?.input && editor.matches(this._activeEditorPane.input)) { this.doHideActiveEditorPane(); } } diff --git a/src/vs/workbench/browser/parts/editor/editorWithViewState.ts b/src/vs/workbench/browser/parts/editor/editorWithViewState.ts index 2f1abb31153..07a13f8955e 100644 --- a/src/vs/workbench/browser/parts/editor/editorWithViewState.ts +++ b/src/vs/workbench/browser/parts/editor/editorWithViewState.ts @@ -17,8 +17,6 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic import { IExtUri } from 'vs/base/common/resources'; import { IDisposable, MutableDisposable } from 'vs/base/common/lifecycle'; import { EditorInput } from 'vs/workbench/common/editor/editorInput'; -import { IEditorOptions } from 'vs/platform/editor/common/editor'; -import { CancellationToken } from 'vs/base/common/cancellation'; /** * Base class of editors that want to store and restore view state. @@ -65,14 +63,6 @@ export abstract class AbstractEditorWithViewState extends Edit } } - override async setInput(input: EditorInput, options: IEditorOptions | undefined, context: IEditorOpenContext, token: CancellationToken): Promise { - - // Preserve current input view state before opening new - this.updateEditorViewState(this.input); - - await super.setInput(input, options, context, token); - } - override clearInput(): void { // Preserve current input view state before clearing diff --git a/src/vs/workbench/browser/workbench.contribution.ts b/src/vs/workbench/browser/workbench.contribution.ts index 7dbe26ca935..cfc14325479 100644 --- a/src/vs/workbench/browser/workbench.contribution.ts +++ b/src/vs/workbench/browser/workbench.contribution.ts @@ -241,6 +241,11 @@ const registry = Registry.as(ConfigurationExtensions.Con 'default': false, 'description': localize('perEditorGroup', "Controls if the limit of maximum opened editors should apply per editor group or across all editor groups.") }, + 'workbench.editor.experimentalDisableClearInputOnSetInput': { + 'type': 'boolean', + 'default': false, + 'description': localize('experimentalDisableClearInputOnSetInput', "Experimental setting: do not change unless instructed.") + }, 'workbench.commandPalette.history': { 'type': 'number', 'description': localize('commandHistory', "Controls the number of recently used commands to keep in history for the command palette. Set to 0 to disable command history."), diff --git a/src/vs/workbench/common/editor.ts b/src/vs/workbench/common/editor.ts index 682522d5688..b63bbd6a36d 100644 --- a/src/vs/workbench/common/editor.ts +++ b/src/vs/workbench/common/editor.ts @@ -864,7 +864,8 @@ interface IEditorPartConfiguration { decorations?: { badges?: boolean; colors?: boolean; - } + }, + experimentalDisableClearInputOnSetInput?: boolean; } export interface IEditorPartOptions extends IEditorPartConfiguration { diff --git a/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts b/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts index 31e939f76cb..67683ca4f6e 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts @@ -175,8 +175,6 @@ export class NotebookEditor extends EditorPane { this.inputListener.value = input.onDidChangeCapabilities(() => this.onDidChangeInputCapabilities(input)); - this._saveEditorViewState(this.input); - this._widgetDisposableStore.clear(); // there currently is a widget which we still own so diff --git a/src/vs/workbench/contrib/welcome/walkThrough/browser/walkThroughPart.ts b/src/vs/workbench/contrib/welcome/walkThrough/browser/walkThroughPart.ts index b1c5d45c47a..f0b72fb52c0 100644 --- a/src/vs/workbench/contrib/welcome/walkThrough/browser/walkThroughPart.ts +++ b/src/vs/workbench/contrib/welcome/walkThrough/browser/walkThroughPart.ts @@ -268,10 +268,6 @@ export class WalkThroughPart extends EditorPane { } override setInput(input: WalkThroughInput, options: IEditorOptions | undefined, context: IEditorOpenContext, token: CancellationToken): Promise { - if (this.input instanceof WalkThroughInput) { - this.saveTextEditorViewState(this.input); - } - const store = new DisposableStore(); this.contentDisposables.push(store);