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.
This commit is contained in:
Benjamin Pasero
2024-01-15 15:30:41 +01:00
committed by GitHub
parent ee5f2226b7
commit b94347eebf
3 changed files with 20 additions and 20 deletions
@@ -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<void> {
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
@@ -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'
);
}
@@ -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<IEditorPartOptionsChangeEvent>;
/**
* 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<IEditorPartOptionsChangeEvent>;
/**
* Opens a new window with a full editor part instantiated
* in there at the optional position and size on screen.