Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a setting to ignore dirty tabs in workbench.editor.limit.value. #144545

Merged
merged 6 commits into from Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/vs/workbench/browser/parts/editor/editorsObserver.ts
Expand Up @@ -339,12 +339,28 @@ export class EditorsObserver extends Disposable {
}

private async doEnsureOpenedEditorsLimit(limit: number, mostRecentEditors: IEditorIdentifier[], exclude?: IEditorIdentifier): Promise<void> {
if (limit >= mostRecentEditors.length) {

// 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.editorGroupsService.partOptions.limit?.excludeDirty) {
mostRecentEditorsCountingForLimit = mostRecentEditors.filter(({ editor }) => {
if (editor.isDirty() && !editor.isSaving()) {
return false;
}

return true;
});
} else {
mostRecentEditorsCountingForLimit = mostRecentEditors;
}

if (limit >= mostRecentEditorsCountingForLimit.length) {
return; // only if opened editors exceed setting and is valid and enabled
}

// Extract least recently used editors that can be closed
const leastRecentlyClosableEditors = mostRecentEditors.reverse().filter(({ editor, groupId }) => {
const leastRecentlyClosableEditors = mostRecentEditorsCountingForLimit.reverse().filter(({ editor, groupId }) => {
if (editor.isDirty() && !editor.isSaving()) {
return false; // not dirty editors (unless in the process of saving)
}
Expand All @@ -361,7 +377,7 @@ export class EditorsObserver extends Disposable {
});

// Close editors until we reached the limit again
let editorsToCloseCount = mostRecentEditors.length - limit;
let editorsToCloseCount = mostRecentEditorsCountingForLimit.length - limit;
const mapGroupToEditorsToClose = new Map<GroupIdentifier, EditorInput[]>();
for (const { groupId, editor } of leastRecentlyClosableEditors) {
let editorsInGroupToClose = mapGroupToEditorsToClose.get(groupId);
Expand Down
5 changes: 5 additions & 0 deletions src/vs/workbench/browser/workbench.contribution.ts
Expand Up @@ -252,6 +252,11 @@ const registry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Con
'exclusiveMinimum': 0,
'markdownDescription': localize('limitEditorsMaximum', "Controls the maximum number of opened editors. Use the `#workbench.editor.limit.perEditorGroup#` setting to control this limit per editor group or across all groups.")
},
'workbench.editor.limit.excludeDirty': {
'type': 'boolean',
'default': false,
'description': localize('limitEditorsExcludeDirty', "Controls if the maximum number of opened editors should exclude dirty editors for counting towards the configured limit.")
},
'workbench.editor.limit.perEditorGroup': {
'type': 'boolean',
'default': false,
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/common/editor.ts
Expand Up @@ -968,6 +968,7 @@ interface IEditorPartConfiguration {
splitOnDragAndDrop?: boolean;
limit?: {
enabled?: boolean;
excludeDirty?: boolean;
value?: number;
perEditorGroup?: boolean;
};
Expand Down