diff --git a/CHANGELOG.md b/CHANGELOG.md index b2c972df6c403..0c922848c6fbf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ## [Unreleased] +### Added + +- Adds an _Open Changes_ button to commits in the file history quick pick menu — closes [#2641](https://github.com/gitkraken/vscode-gitlens/issues/2641) thanks to [PR #2800](https://github.com/gitkraken/vscode-gitlens/pull/2800) by Omar Ghazi ([@omarfesal](https://github.com/omarfesal)) + ## [14.2.1] - 2023-08-10 ### Added diff --git a/README.md b/README.md index b965b69398b11..19ef4e0bfe781 100644 --- a/README.md +++ b/README.md @@ -345,6 +345,7 @@ A big thanks to the people that have contributed to this project 🙏❤️: - Cory Forsyth ([@bantic](https://github.com/bantic)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=bantic) - John Gee ([@shadowspawn](https://github.com/shadowspawn)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=shadowspawn) - Geoffrey ([@g3offrey](https://github.com/g3offrey)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=g3offrey) +- Omar Ghazi ([@omarfesal](https://github.com/omarfesal)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=omarfesal) - Neil Ghosh ([@neilghosh](https://github.com/neilghosh)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=neilghosh) - Guillaume Rozan ([@grozan](https://github.com/grozan)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=grozan) - Guillem González Vela ([@guillemglez](https://github.com/guillemglez)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=guillemglez) diff --git a/src/commands/quickCommand.steps.ts b/src/commands/quickCommand.steps.ts index 8e412180613d4..db9043c5c0eb5 100644 --- a/src/commands/quickCommand.steps.ts +++ b/src/commands/quickCommand.steps.ts @@ -98,7 +98,7 @@ import { isSubscriptionPaidPlan, isSubscriptionPreviewTrialExpired } from '../su import { filterMap, intersection, isStringArray } from '../system/array'; import { configuration } from '../system/configuration'; import { formatPath } from '../system/formatPath'; -import { map } from '../system/iterable'; +import { first, map } from '../system/iterable'; import { getSettledValue } from '../system/promise'; import { pad, pluralize, truncate } from '../system/string'; import { openWorkspace, OpenWorkspaceLocation } from '../system/utils'; @@ -1059,27 +1059,32 @@ export async function* pickCommitStep< }, ): AsyncStepResultGenerator { function getItems(log: GitLog | undefined) { - return log == null - ? [createDirectiveQuickPickItem(Directive.Back, true), createDirectiveQuickPickItem(Directive.Cancel)] - : [ - ...map(log.commits.values(), commit => - createCommitQuickPickItem( - commit, - picked != null && - (typeof picked === 'string' ? commit.ref === picked : picked.includes(commit.ref)), - { - buttons: [ - ShowDetailsViewQuickInputButton, - RevealInSideBarQuickInputButton, - OpenChangesViewQuickInputButton, - ], - compact: true, - icon: true, - }, - ), - ), - ...(log?.hasMore ? [createDirectiveQuickPickItem(Directive.LoadMore)] : []), - ]; + if (log == null) { + return [createDirectiveQuickPickItem(Directive.Back, true), createDirectiveQuickPickItem(Directive.Cancel)]; + } + + const buttons = [ShowDetailsViewQuickInputButton, RevealInSideBarQuickInputButton]; + + // If these are "file" commits, then add an Open Changes button + if (first(log.commits)?.[1].file != null) { + buttons.splice(0, 0, OpenChangesViewQuickInputButton); + } + + return [ + ...map(log.commits.values(), commit => + createCommitQuickPickItem( + commit, + picked != null && + (typeof picked === 'string' ? commit.ref === picked : picked.includes(commit.ref)), + { + buttons: buttons, + compact: true, + icon: true, + }, + ), + ), + ...(log?.hasMore ? [createDirectiveQuickPickItem(Directive.LoadMore)] : []), + ]; } const step = createPickStep({ @@ -1106,7 +1111,6 @@ export async function* pickCommitStep< ], onDidClickItemButton: (quickpick, button, item) => { if (CommandQuickPickItem.is(item)) return; - const fileName = `${item.item.file?.path}`; switch (button) { case ShowDetailsViewQuickInputButton: @@ -1120,9 +1124,13 @@ export async function* pickCommitStep< expand: true, }); break; - case OpenChangesViewQuickInputButton: - void CommitActions.openChanges(fileName, item.item, {}); + case OpenChangesViewQuickInputButton: { + const path = item.item.file?.path; + if (path != null) { + void CommitActions.openChanges(path, item.item); + } break; + } } }, onDidClickButton: (quickpick, button) => {