editors - clearInput before setInput (#34697)

This commit is contained in:
Benjamin Pasero 2021-11-21 14:04:28 +01:00
parent 6825c88670
commit 2e636ded90
No known key found for this signature in database
GPG key ID: E6380CC4C8219E65
9 changed files with 25 additions and 23 deletions

View file

@ -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 {

View file

@ -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

View file

@ -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`.

View file

@ -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();
}
}

View file

@ -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<T extends object> extends Edit
}
}
override async setInput(input: EditorInput, options: IEditorOptions | undefined, context: IEditorOpenContext, token: CancellationToken): Promise<void> {
// 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

View file

@ -241,6 +241,11 @@ const registry = Registry.as<IConfigurationRegistry>(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."),

View file

@ -864,7 +864,8 @@ interface IEditorPartConfiguration {
decorations?: {
badges?: boolean;
colors?: boolean;
}
},
experimentalDisableClearInputOnSetInput?: boolean;
}
export interface IEditorPartOptions extends IEditorPartConfiguration {

View file

@ -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

View file

@ -268,10 +268,6 @@ export class WalkThroughPart extends EditorPane {
}
override setInput(input: WalkThroughInput, options: IEditorOptions | undefined, context: IEditorOpenContext, token: CancellationToken): Promise<void> {
if (this.input instanceof WalkThroughInput) {
this.saveTextEditorViewState(this.input);
}
const store = new DisposableStore();
this.contentDisposables.push(store);