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

Git - add command to close all unmodified editors #205278

Merged
merged 2 commits into from
Feb 15, 2024
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
6 changes: 6 additions & 0 deletions extensions/git/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,12 @@
"category": "Git",
"enablement": "!operationInProgress"
},
{
"command": "git.closeAllUnmodifiedEditors",
"title": "%command.closeAllUnmodifiedEditors%",
"category": "Git",
"enablement": "!operationInProgress"
},
{
"command": "git.api.getRepositories",
"title": "%command.api.getRepositories%",
Expand Down
1 change: 1 addition & 0 deletions extensions/git/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"command.cleanAllTracked": "Discard All Tracked Changes",
"command.cleanAllUntracked": "Discard All Untracked Changes",
"command.closeAllDiffEditors": "Close All Diff Editors",
"command.closeAllUnmodifiedEditors": "Close All Unmodified Editors",
"command.commit": "Commit",
"command.commitAmend": "Commit (Amend)",
"command.commitSigned": "Commit (Signed Off)",
Expand Down
33 changes: 32 additions & 1 deletion extensions/git/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import * as os from 'os';
import * as path from 'path';
import { Command, commands, Disposable, LineChange, MessageOptions, Position, ProgressLocation, QuickPickItem, Range, SourceControlResourceState, TextDocumentShowOptions, TextEditor, Uri, ViewColumn, window, workspace, WorkspaceEdit, WorkspaceFolder, TimelineItem, env, Selection, TextDocumentContentProvider, InputBoxValidationSeverity, TabInputText, TabInputTextMerge, QuickPickItemKind, TextDocument, LogOutputChannel, l10n, Memento, UIKind, QuickInputButton, ThemeIcon, SourceControlHistoryItem, SourceControl, InputBoxValidationMessage } from 'vscode';
import { Command, commands, Disposable, LineChange, MessageOptions, Position, ProgressLocation, QuickPickItem, Range, SourceControlResourceState, TextDocumentShowOptions, TextEditor, Uri, ViewColumn, window, workspace, WorkspaceEdit, WorkspaceFolder, TimelineItem, env, Selection, TextDocumentContentProvider, InputBoxValidationSeverity, TabInputText, TabInputTextMerge, QuickPickItemKind, TextDocument, LogOutputChannel, l10n, Memento, UIKind, QuickInputButton, ThemeIcon, SourceControlHistoryItem, SourceControl, InputBoxValidationMessage, Tab, TabInputNotebook } from 'vscode';
import TelemetryReporter from '@vscode/extension-telemetry';
import { uniqueNamesGenerator, adjectives, animals, colors, NumberDictionary } from '@joaomoreno/unique-names-generator';
import { ForcePushMode, GitErrorCodes, Ref, RefType, Status, CommitOptions, RemoteSourcePublisher, Remote } from './api/git';
Expand Down Expand Up @@ -3994,6 +3994,37 @@ export class CommandCenter {
repository.closeDiffEditors(undefined, undefined, true);
}

@command('git.closeAllUnmodifiedEditors')
closeUnmodifiedEditors(): void {
const editorTabsToClose: Tab[] = [];

// Collect all modified files
const modifiedFiles: string[] = [];
for (const repository of this.model.repositories) {
modifiedFiles.push(...repository.indexGroup.resourceStates.map(r => r.resourceUri.fsPath));
modifiedFiles.push(...repository.workingTreeGroup.resourceStates.map(r => r.resourceUri.fsPath));
modifiedFiles.push(...repository.untrackedGroup.resourceStates.map(r => r.resourceUri.fsPath));
modifiedFiles.push(...repository.mergeGroup.resourceStates.map(r => r.resourceUri.fsPath));
}

// Collect all editor tabs that are not dirty and not modified
for (const tab of window.tabGroups.all.map(g => g.tabs).flat()) {
if (tab.isDirty) {
continue;
}

if (tab.input instanceof TabInputText || tab.input instanceof TabInputNotebook) {
const { uri } = tab.input;
if (!modifiedFiles.find(p => pathEquals(p, uri.fsPath))) {
editorTabsToClose.push(tab);
}
}
}

// Close editors
window.tabGroups.close(editorTabsToClose, true);
}

@command('git.openRepositoriesInParentFolders')
async openRepositoriesInParentFolders(): Promise<void> {
const parentRepositories: string[] = [];
Expand Down