Skip to content

Commit 2293c3d

Browse files
authored
SCM - Move "View Changes" action into core (microsoft#223485)
* Move "View Changes" action into core * Verify that the first/last history item group are on the same branch
1 parent 38a7fcd commit 2293c3d

File tree

2 files changed

+68
-20
lines changed

2 files changed

+68
-20
lines changed

extensions/git/package.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1959,20 +1959,15 @@
19591959
}
19601960
],
19611961
"scm/historyItem/context": [
1962-
{
1963-
"command": "git.viewCommit",
1964-
"when": "scmProvider == git && config.multiDiffEditor.experimental.enabled",
1965-
"group": "1_view@1"
1966-
},
19671962
{
19681963
"command": "git.copyCommitId",
19691964
"when": "scmProvider == git && !listMultiSelection",
1970-
"group": "3_copy@1"
1965+
"group": "1_copy@1"
19711966
},
19721967
{
19731968
"command": "git.copyCommitMessage",
19741969
"when": "scmProvider == git && !listMultiSelection",
1975-
"group": "3_copy@2"
1970+
"group": "1_copy@2"
19761971
}
19771972
],
19781973
"scm/incomingChanges": [

src/vs/workbench/contrib/scm/browser/scmViewPane.ts

Lines changed: 66 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -860,17 +860,16 @@ class HistoryItemActionRunner2 extends ActionRunner {
860860
const selection = this.getSelectedHistoryItems();
861861
const contextIsSelected = selection.some(s => s === context);
862862
if (contextIsSelected && selection.length > 1) {
863-
args.push(...[selection[0], selection[selection.length - 1]]
864-
.map(h => (
865-
{
866-
id: h.historyItemViewModel.historyItem.id,
867-
parentIds: h.historyItemViewModel.historyItem.parentIds,
868-
message: h.historyItemViewModel.historyItem.message,
869-
author: h.historyItemViewModel.historyItem.author,
870-
icon: h.historyItemViewModel.historyItem.icon,
871-
timestamp: h.historyItemViewModel.historyItem.timestamp,
872-
statistics: h.historyItemViewModel.historyItem.statistics,
873-
} satisfies ISCMHistoryItem)));
863+
args.push(...selection.map(h => (
864+
{
865+
id: h.historyItemViewModel.historyItem.id,
866+
parentIds: h.historyItemViewModel.historyItem.parentIds,
867+
message: h.historyItemViewModel.historyItem.message,
868+
author: h.historyItemViewModel.historyItem.author,
869+
icon: h.historyItemViewModel.historyItem.icon,
870+
timestamp: h.historyItemViewModel.historyItem.timestamp,
871+
statistics: h.historyItemViewModel.historyItem.statistics,
872+
} satisfies ISCMHistoryItem)));
874873
} else {
875874
args.push({
876875
id: context.historyItemViewModel.historyItem.id,
@@ -1905,6 +1904,60 @@ registerAction2(class extends Action2 {
19051904
}
19061905
});
19071906

1907+
registerAction2(class extends Action2 {
1908+
constructor() {
1909+
super({
1910+
id: 'workbench.scm.action.scm.viewChanges',
1911+
title: localize('viewChanges', "View Changes"),
1912+
f1: false,
1913+
menu: [
1914+
{
1915+
id: MenuId.SCMChangesContext,
1916+
group: '0_view',
1917+
when: ContextKeyExpr.equals('config.multiDiffEditor.experimental.enabled', true)
1918+
}
1919+
]
1920+
});
1921+
}
1922+
1923+
override async run(accessor: ServicesAccessor, provider: ISCMProvider, ...historyItems: ISCMHistoryItem[]) {
1924+
const commandService = accessor.get(ICommandService);
1925+
1926+
if (!provider || historyItems.length === 0) {
1927+
return;
1928+
}
1929+
1930+
const historyItem = historyItems[0];
1931+
const historyItemLast = historyItems[historyItems.length - 1];
1932+
const historyProvider = provider.historyProvider.get();
1933+
1934+
if (historyItems.length > 1) {
1935+
const ancestor = await historyProvider?.resolveHistoryItemGroupCommonAncestor2([historyItem.id, historyItemLast.id]);
1936+
if (!ancestor || (ancestor !== historyItem.id && ancestor !== historyItemLast.id)) {
1937+
return;
1938+
}
1939+
}
1940+
1941+
const historyItemParentId = historyItemLast.parentIds.length > 0 ? historyItemLast.parentIds[0] : undefined;
1942+
const historyItemChanges = await historyProvider?.provideHistoryItemChanges(historyItem.id, historyItemParentId);
1943+
1944+
if (!historyItemChanges?.length) {
1945+
return;
1946+
}
1947+
1948+
const title = historyItems.length === 1 ?
1949+
`${historyItems[0].id.substring(0, 8)} - ${historyItems[0].message}` :
1950+
localize('historyItemChangesEditorTitle', "All Changes ({0} ↔ {1})", historyItem.id.substring(0, 8), historyItemLast.id.substring(0, 8));
1951+
1952+
const rootUri = provider.rootUri;
1953+
const multiDiffSourceUri = rootUri ?
1954+
rootUri.with({ scheme: 'scm-history-item', path: `${rootUri.path}/${historyItem.id}..${historyItemParentId}` }) :
1955+
URI.from({ scheme: 'scm-history-item', path: `${provider.label}/${historyItem.id}..${historyItemParentId}` }, true);
1956+
1957+
commandService.executeCommand('_workbench.openMultiDiffEditor', { title, multiDiffSourceUri, resources: historyItemChanges });
1958+
}
1959+
});
1960+
19081961
class RepositoryVisibilityAction extends Action2 {
19091962

19101963
private repository: ISCMRepository;
@@ -3367,8 +3420,8 @@ export class SCMViewPane extends ViewPane {
33673420

33683421
const rootUri = e.element.repository.provider.rootUri;
33693422
const multiDiffSourceUri = rootUri ?
3370-
rootUri.with({ scheme: 'scm-history-item', path: `${rootUri.path}/${historyItem.id}` }) :
3371-
{ scheme: 'scm-history-item', path: `${e.element.repository.provider.label}/${historyItem.id}` };
3423+
rootUri.with({ scheme: 'scm-history-item', path: `${rootUri.path}/${historyItem.id}..${historyItemParentId}` }) :
3424+
URI.from({ scheme: 'scm-history-item', path: `${e.element.repository.provider.label}/${historyItem.id}..${historyItemParentId}` }, true);
33723425

33733426
await this.commandService.executeCommand('_workbench.openMultiDiffEditor', { title, multiDiffSourceUri, resources: historyItemChanges });
33743427
}

0 commit comments

Comments
 (0)