From b94347eebfc0484b23ee7bb011b8a7921cd8dfa9 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Mon, 15 Jan 2024 15:30:41 +0100 Subject: [PATCH] debt - ensure `partOptions` are accessible only from service (#202511) Otherwise we have a potential timing problem before the options propagate down to the floating windows. --- .../browser/parts/editor/editorsObserver.ts | 14 ++++++------- .../browser/parts/titlebar/titlebarPart.ts | 6 +++--- .../editor/common/editorGroupsService.ts | 20 +++++++++---------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/vs/workbench/browser/parts/editor/editorsObserver.ts b/src/vs/workbench/browser/parts/editor/editorsObserver.ts index c6a09b4fcfd..ac30da415d2 100644 --- a/src/vs/workbench/browser/parts/editor/editorsObserver.ts +++ b/src/vs/workbench/browser/parts/editor/editorsObserver.ts @@ -97,7 +97,7 @@ export class EditorsObserver extends Disposable { private registerListeners(): void { this._register(this.editorGroupsContainer.onDidAddGroup(group => this.onGroupAdded(group))); - this._register(this.editorGroupsContainer.onDidChangeEditorPartOptions(e => this.onDidChangeEditorPartOptions(e))); + this._register(this.editorGroupService.onDidChangeEditorPartOptions(e => this.onDidChangeEditorPartOptions(e))); this._register(this.storageService.onWillSaveState(() => this.saveState())); } @@ -310,17 +310,17 @@ export class EditorsObserver extends Disposable { private async ensureOpenedEditorsLimit(exclude: IEditorIdentifier | undefined, groupId?: GroupIdentifier): Promise { if ( - !this.editorGroupsContainer.partOptions.limit?.enabled || - typeof this.editorGroupsContainer.partOptions.limit.value !== 'number' || - this.editorGroupsContainer.partOptions.limit.value <= 0 + !this.editorGroupService.partOptions.limit?.enabled || + typeof this.editorGroupService.partOptions.limit.value !== 'number' || + this.editorGroupService.partOptions.limit.value <= 0 ) { return; // return early if not enabled or invalid } - const limit = this.editorGroupsContainer.partOptions.limit.value; + const limit = this.editorGroupService.partOptions.limit.value; // In editor group - if (this.editorGroupsContainer.partOptions.limit?.perEditorGroup) { + if (this.editorGroupService.partOptions.limit?.perEditorGroup) { // For specific editor groups if (typeof groupId === 'number') { @@ -349,7 +349,7 @@ export class EditorsObserver extends Disposable { // Check for `excludeDirty` setting and apply it by excluding // any recent editor that is dirty from the opened editors limit let mostRecentEditorsCountingForLimit: IEditorIdentifier[]; - if (this.editorGroupsContainer.partOptions.limit?.excludeDirty) { + if (this.editorGroupService.partOptions.limit?.excludeDirty) { mostRecentEditorsCountingForLimit = mostRecentEditors.filter(({ editor }) => { if ((editor.isDirty() && !editor.isSaving()) || editor.hasCapability(EditorInputCapabilities.Scratchpad)) { return false; // not dirty editors (unless in the process of saving) or scratchpads diff --git a/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts b/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts index c66a4dabd81..3ca421396a6 100644 --- a/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts +++ b/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts @@ -701,10 +701,10 @@ export class BrowserTitlebarPart extends Part implements ITitlebarPart { } private get editorActionsEnabled(): boolean { - return this.editorGroupsContainer.partOptions.editorActionsLocation === 'titleBar' || + return this.editorGroupService.partOptions.editorActionsLocation === 'titleBar' || ( - this.editorGroupsContainer.partOptions.editorActionsLocation === 'default' && - this.editorGroupsContainer.partOptions.showTabs === 'none' + this.editorGroupService.partOptions.editorActionsLocation === 'default' && + this.editorGroupService.partOptions.showTabs === 'none' ); } diff --git a/src/vs/workbench/services/editor/common/editorGroupsService.ts b/src/vs/workbench/services/editor/common/editorGroupsService.ts index f2d29edc549..bd39f81d3cc 100644 --- a/src/vs/workbench/services/editor/common/editorGroupsService.ts +++ b/src/vs/workbench/services/editor/common/editorGroupsService.ts @@ -410,16 +410,6 @@ export interface IEditorGroupsContainer { */ copyGroup(group: IEditorGroup | GroupIdentifier, location: IEditorGroup | GroupIdentifier, direction: GroupDirection): IEditorGroup; - /** - * Access the options of the editor part. - */ - readonly partOptions: IEditorPartOptions; - - /** - * An event that notifies when editor part options change. - */ - readonly onDidChangeEditorPartOptions: Event; - /** * Allows to register a drag and drop target for editors * on the provided `container`. @@ -526,6 +516,16 @@ export interface IEditorGroupsService extends IEditorGroupsContainer { */ getPart(container: unknown /* HTMLElement */): IEditorPart; + /** + * Access the options of the editor part. + */ + readonly partOptions: IEditorPartOptions; + + /** + * An event that notifies when editor part options change. + */ + readonly onDidChangeEditorPartOptions: Event; + /** * Opens a new window with a full editor part instantiated * in there at the optional position and size on screen.