Skip to content

Commit 07c3afc

Browse files
committed
Fixes #4778 selecting revs/refs in views
- Switches to a unified comparison picker dialog for selecting refs - Simplifies command handling and context state management - Removes the custom compare picker node and related tree view logic
1 parent c750049 commit 07c3afc

File tree

11 files changed

+60
-248
lines changed

11 files changed

+60
-248
lines changed

contributions.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8169,7 +8169,7 @@
81698169
{
81708170
"when": "webviewItem =~ /gitlens:file\\b/ && !listMultiSelection && gitlens:views:canCompare:file && webview == gitlens.views.commitDetails",
81718171
"group": "4_gitlens_compare",
8172-
"order": 99
8172+
"order": 98
81738173
}
81748174
]
81758175
}
@@ -8181,7 +8181,7 @@
81818181
{
81828182
"when": "webviewItem =~ /gitlens:file\\b/ && !listMultiSelection && gitlens:views:canCompare:file && webview == gitlens.views.graphDetails",
81838183
"group": "4_gitlens_compare",
8184-
"order": 99
8184+
"order": 98
81858185
}
81868186
]
81878187
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25124,12 +25124,12 @@
2512425124
{
2512525125
"command": "gitlens.views.compareFileWithSelected:commitDetails",
2512625126
"when": "webviewItem =~ /gitlens:file\\b/ && !listMultiSelection && gitlens:views:canCompare:file && webview == gitlens.views.commitDetails",
25127-
"group": "4_gitlens_compare@99"
25127+
"group": "4_gitlens_compare@98"
2512825128
},
2512925129
{
2513025130
"command": "gitlens.views.compareFileWithSelected:graphDetails",
2513125131
"when": "webviewItem =~ /gitlens:file\\b/ && !listMultiSelection && gitlens:views:canCompare:file && webview == gitlens.views.graphDetails",
25132-
"group": "4_gitlens_compare@99"
25132+
"group": "4_gitlens_compare@98"
2513325133
},
2513425134
{
2513525135
"command": "gitlens.views.selectFileForCompare:commitDetails",

src/commands/compareWith.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import type { TextEditor, Uri } from 'vscode';
22
import type { Container } from '../container';
3+
import { createReference } from '../git/utils/reference.utils';
34
import { showGenericErrorMessage } from '../messages';
5+
import { showComparisonPicker } from '../quickpicks/comparisonPicker';
46
import { getBestRepositoryOrShowPicker } from '../quickpicks/repositoryPicker';
57
import { command } from '../system/-webview/command';
68
import { Logger } from '../system/logger';
@@ -68,10 +70,19 @@ export class CompareWithCommand extends ActiveEditorCommand {
6870
const repoPath = (await getBestRepositoryOrShowPicker(this.container, uri, editor, title))?.path;
6971
if (!repoPath) return;
7072

73+
if (args.ref1 == null || args.ref2 == null) {
74+
const result = await showComparisonPicker(this.container, repoPath, {
75+
head: args.ref1 != null ? createReference(args.ref1, repoPath) : undefined,
76+
base: args.ref2 != null ? createReference(args.ref2, repoPath) : undefined,
77+
});
78+
if (result == null) return;
79+
80+
args.ref1 = result.head.ref;
81+
args.ref2 = result.base.ref;
82+
}
83+
7184
if (args.ref1 != null && args.ref2 != null) {
7285
await this.container.views.searchAndCompare.compare(repoPath, args.ref1, args.ref2);
73-
} else {
74-
this.container.views.searchAndCompare.selectForCompare(repoPath, args.ref1, { prompt: true });
7586
}
7687
} catch (ex) {
7788
Logger.error(ex, 'CompareWithCommmand');

src/constants.commands.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ type InternalScmGroupedViewCommands =
9090
| 'gitlens.views.scm.grouped.welcome.dismiss'
9191
| 'gitlens.views.scm.grouped.welcome.restore';
9292

93-
type InternalSearchAndCompareViewCommands = 'gitlens.views.searchAndCompare.compareWithSelected';
94-
9593
type InternalTimelineWebviewViewCommands = 'gitlens.views.timeline.openInTab';
9694

9795
type InternalViewCommands = 'gitlens.views.loadMoreChildren';
@@ -165,7 +163,6 @@ type InternalGlCommands =
165163
| InternalPlusCommands
166164
| InternalPullRequestViewCommands
167165
| InternalScmGroupedViewCommands
168-
| InternalSearchAndCompareViewCommands
169166
| InternalTimelineWebviewViewCommands
170167
| InternalViewCommands
171168
| InternalWalkthroughCommands;

src/constants.context.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ import type { OrgAIProviders } from './plus/gk/models/organization';
99
import type { PromoKeys } from './plus/gk/models/promo';
1010
import type { SubscriptionPlanIds } from './plus/gk/models/subscription';
1111

12+
interface CompareSelectedInfo {
13+
label: string;
14+
ref: string;
15+
repoPath: string;
16+
}
17+
1218
interface CompareSelectedFileInfo {
1319
ref: string;
1420
repoPath: string | undefined;
@@ -54,7 +60,7 @@ export type ContextKeys = {
5460
'gitlens:tabs:blameable': Uri[];
5561
'gitlens:tabs:tracked': Uri[];
5662
'gitlens:untrusted': boolean;
57-
'gitlens:views:canCompare': boolean;
63+
'gitlens:views:canCompare': CompareSelectedInfo;
5864
'gitlens:views:canCompare:file': CompareSelectedFileInfo;
5965
'gitlens:views:commits:filtered': boolean;
6066
'gitlens:views:commits:hideMergeCommits': boolean;

src/constants.views.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ export type TreeViewNodeTypes =
151151
| 'autolink'
152152
| 'branch-tag-folder'
153153
| 'branches'
154-
| 'compare-picker'
155154
| 'contributor'
156155
| 'contributors'
157156
| 'conflict-files'

src/views/nodes/abstract/viewNode.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ export const enum ContextValues {
5555
CommitsCurrentBranch = 'gitlens:commits:current-branch',
5656
Compare = 'gitlens:compare',
5757
CompareBranch = 'gitlens:compare:branch',
58-
ComparePicker = 'gitlens:compare:picker',
59-
ComparePickerWithRef = 'gitlens:compare:picker:ref',
6058
CompareResults = 'gitlens:compare:results',
6159
CompareResultsCommits = 'gitlens:compare:results:commits',
6260
Contributor = 'gitlens:contributor',

src/views/nodes/comparePickerNode.ts

Lines changed: 0 additions & 70 deletions
This file was deleted.

src/views/nodes/utils/-webview/node.utils.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import type { CommitNode } from '../../commitNode';
2020
import type { PagerNode } from '../../common';
2121
import { MessageNode } from '../../common';
2222
import type { CompareBranchNode } from '../../compareBranchNode';
23-
import type { ComparePickerNode } from '../../comparePickerNode';
2423
import type { CompareResultsNode } from '../../compareResultsNode';
2524
import type { ContributorNode } from '../../contributorNode';
2625
import type { ContributorsNode } from '../../contributorsNode';
@@ -82,8 +81,6 @@ export type TreeViewNodesByType = {
8281
? CommitsCurrentBranchNode
8382
: T extends 'compare-branch'
8483
? CompareBranchNode
85-
: T extends 'compare-picker'
86-
? ComparePickerNode
8784
: T extends 'compare-results'
8885
? CompareResultsNode
8986
: T extends 'conflict-current-changes'

0 commit comments

Comments
 (0)