Add command to close all diff editors

This commit is contained in:
Ladislau Szomoru 2022-02-15 11:59:25 +01:00
parent 6e99129744
commit ce46f445c0
No known key found for this signature in database
GPG key ID: 2B88287CB9DB080B
4 changed files with 26 additions and 3 deletions

View file

@ -531,6 +531,11 @@
"title": "%command.rebaseAbort%",
"category": "Git"
},
{
"command": "git.closeAllDiffEditors",
"title": "%command.closeAllDiffEditors%",
"category": "Git"
},
{
"command": "git.api.getRepositories",
"title": "%command.api.getRepositories%",
@ -933,6 +938,10 @@
"command": "git.timeline.compareWithSelected",
"when": "false"
},
{
"command": "git.closeAllDiffEditors",
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0"
},
{
"command": "git.api.getRepositories",
"when": "false"
@ -2231,7 +2240,9 @@
"default",
"download"
],
"tags": ["experimental"],
"tags": [
"experimental"
],
"scope": "machine",
"description": "%config.experimental.installGuide%",
"default": "default"

View file

@ -29,6 +29,7 @@
"command.cleanAll": "Discard All Changes",
"command.cleanAllTracked": "Discard All Tracked Changes",
"command.cleanAllUntracked": "Discard All Untracked Changes",
"command.closeAllDiffEditors": "Close All Diff Editors",
"command.commit": "Commit",
"command.commitStaged": "Commit Staged",
"command.commitEmpty": "Commit Empty",

View file

@ -2753,6 +2753,17 @@ export class CommandCenter {
}
}
@command('git.closeAllDiffEditors', { repository: true })
closeDiffEditors(repository: Repository): void {
const resources = [
...repository.indexGroup.resourceStates.map(r => r.resourceUri.fsPath),
...repository.workingTreeGroup.resourceStates.map(r => r.resourceUri.fsPath),
...repository.untrackedGroup.resourceStates.map(r => r.resourceUri.fsPath)
];
repository.closeDiffEditors(resources, resources, true);
}
private createCommand(id: string, key: string, method: Function, options: ScmCommandOptions): (...args: any[]) => any {
const result = (...args: any[]) => {
let result: Promise<any>;

View file

@ -1266,9 +1266,9 @@ export class Repository implements Disposable {
});
}
private closeDiffEditors(indexResources: string[], workingTreeResources: string[]): void {
closeDiffEditors(indexResources: string[], workingTreeResources: string[], ignoreSetting: boolean = false): void {
const config = workspace.getConfiguration('git', Uri.file(this.root));
if (!config.get<boolean>('closeDiffOnOperation', false)) { return; }
if (!config.get<boolean>('closeDiffOnOperation', false) && !ignoreSetting) { return; }
const diffEditorTabsToClose: Tab[] = [];