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 stage/unstage actions to the multi-diff editor #202297

Merged
merged 4 commits into from
Jan 12, 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
40 changes: 40 additions & 0 deletions extensions/git/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"tabInputTextMerge",
"timeline",
"contribMergeEditorMenus",
"contribMultiDiffEditorMenus",
"contribSourceControlInputBoxMenu",
"contribSourceControlHistoryItemMenu"
],
Expand Down Expand Up @@ -195,6 +196,13 @@
"icon": "$(add)",
"enablement": "!operationInProgress"
},
{
"command": "git.stageFile",
"title": "%command.stage%",
"category": "Git",
"icon": "$(add)",
"enablement": "!operationInProgress"
},
{
"command": "git.revertChange",
"title": "%command.revertChange%",
Expand Down Expand Up @@ -222,6 +230,13 @@
"category": "Git",
"enablement": "!operationInProgress"
},
{
"command": "git.unstageFile",
"title": "%command.unstage%",
"category": "Git",
"icon": "$(remove)",
"enablement": "!operationInProgress"
},
{
"command": "git.clean",
"title": "%command.clean%",
Expand Down Expand Up @@ -1267,6 +1282,14 @@
{
"command": "git.openCommit",
"when": "false"
},
{
"command": "git.stageFile",
"when": "false"
},
{
"command": "git.unstageFile",
"when": "false"
}
],
"scm/title": [
Expand Down Expand Up @@ -1818,6 +1841,23 @@
"when": "config.git.enabled && !git.missing && !isInDiffEditor && !isMergeEditor && resource in git.mergeChanges"
}
],
"multiDiffEditor/resource/title": [
{
"command": "git.stageFile",
"group": "navigation",
"when": "scmProvider == git && scmResourceGroup == workingTree"
},
{
"command": "git.stageFile",
"group": "navigation",
"when": "scmProvider == git && scmResourceGroup == untracked"
},
{
"command": "git.unstageFile",
"group": "navigation",
"when": "scmProvider == git && scmResourceGroup == index"
}
],
"scm/change/title": [
{
"command": "git.stageChange",
Expand Down
47 changes: 47 additions & 0 deletions extensions/git/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1509,6 +1509,30 @@ export class CommandCenter {
await this._stageChanges(textEditor, selectedChanges);
}

@command('git.stageFile')
async stageFile(uri: Uri): Promise<void> {
if (!uri) {
return;
}

const repository = this.model.getRepository(uri);
if (!repository) {
return;
}

const resources = [
...repository.workingTreeGroup.resourceStates,
...repository.untrackedGroup.resourceStates]
.filter(r => r.multiFileDiffEditorModifiedUri?.toString() === uri.toString())
.map(r => r.resourceUri);

if (resources.length === 0) {
return;
}

await repository.add(resources);
}

@command('git.acceptMerge')
async acceptMerge(_uri: Uri | unknown): Promise<void> {
const { activeTab } = window.tabGroups.activeTabGroup;
Expand Down Expand Up @@ -1761,6 +1785,29 @@ export class CommandCenter {
await this.runByRepository(modifiedUri, async (repository, resource) => await repository.stage(resource, result));
}

@command('git.unstageFile')
async unstageFile(uri: Uri): Promise<void> {
if (!uri) {
return;
}

const repository = this.model.getRepository(uri);
if (!repository) {
return;
}

const resources = repository.indexGroup.resourceStates
.filter(r => r.multiFileDiffEditorModifiedUri?.toString() === uri.toString())
.map(r => r.resourceUri);

if (resources.length === 0) {
return;
}

await repository.revert(resources);
}


@command('git.clean')
async clean(...resourceStates: SourceControlResourceState[]): Promise<void> {
// Remove duplicate resources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,12 @@ const apiMenus: IAPIMenu[] = [
description: localize('menus.mergeEditorResult', "The result toolbar of the merge editor"),
proposed: 'contribMergeEditorMenus'
},
{
key: 'multiDiffEditor/resource/title',
id: MenuId.MultiDiffEditorFileToolbar,
description: localize('menus.multiDiffEditorResource', "The resource toolbar in the multi diff editor"),
proposed: 'contribMultiDiffEditorMenus'
}
];

namespace schema {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const allApiProposals = Object.freeze({
contribLabelFormatterWorkspaceTooltip: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.contribLabelFormatterWorkspaceTooltip.d.ts',
contribMenuBarHome: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.contribMenuBarHome.d.ts',
contribMergeEditorMenus: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.contribMergeEditorMenus.d.ts',
contribMultiDiffEditorMenus: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.contribMultiDiffEditorMenus.d.ts',
contribNotebookStaticPreloads: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.contribNotebookStaticPreloads.d.ts',
contribRemoteHelp: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.contribRemoteHelp.d.ts',
contribShareMenu: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.contribShareMenu.d.ts',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

// empty placeholder declaration for `multiDiffEditor/*` menus