Skip to content

Commit 7a61eb1

Browse files
committed
Adds swap comparision command to results view
1 parent 6d2b60b commit 7a61eb1

File tree

10 files changed

+53
-9
lines changed

10 files changed

+53
-9
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
99
- Adds `gitlens.statusBar.reduceFlicker` setting to specify whether to reduce the status bar "flickering" when changing lines by not first clearing the previous blame information — closes [#272](https://github.com/eamodio/vscode-gitlens/issues/272)
1010
- Adds *Compare Index (HEAD) with Branch or Tag...* (`gitlens.explorers.diffHeadWithBranch`) command - compares the index (HEAD) to the selected branch or tag — thanks to [PR #278](https://github.com/eamodio/vscode-gitlens/pull/278) by Geoffrey ([@g3offrey](https://github.com/g3offrey))!
1111
- Adds *Compare Working Tree with Branch or Tag...* (`gitlens.explorers.diffWorkingWithBranch`) command - compares the working tree to the selected branch or tag
12-
- Adds the *Open File* (`gitlens.explorers.openFile`) command to the *GitLens* explorer inline for file nodes
13-
- Adds the *Clear Results* (`gitlen.resultsExplorer.clearResultsNode`) command to the *GitLens Results* view inline for results nodes
12+
- Adds the *Open File* (`gitlens.explorers.openFile`) command to the *GitLens* explorer's inline toolbar for file nodes
13+
- Adds the *Clear Results* (`gitlen.resultsExplorer.clearResultsNode`) command to the *GitLens Results* view's inline toolbar for results nodes
14+
- Adds the *Swap Comparision* (`gitlen.resultsExplorer.swapComparision`) command to the *GitLens Results* view's inline toolbar and context menu for comparision results nodes
1415
- Adds *Push to Commit (via Terminal)* (`gitlens.explorers.terminalPushCommit`) command to commit nodes on the current branch in the *GitLens* explorer
1516

1617
## Changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ The repository view provides a full Git repository explorer, which has the follo
113113
- *Open Commit in Remote* (if available), *Open All Changes*, *Open All Changes with Working Tree*, *Open Files*, *Open Revisions*, *Copy Commit ID to Clipboard*, *Copy Commit Message to Clipboard*, *Show Commit Details*, *Compare with Index (HEAD)*, *Compare with Working Tree*, *Compare with Selected* (when available), *Select for Compare*, *Cherry Pick Commit (via Terminal)* (when available), *Push to Commit (via Terminal)* (when available), *Revert Commit (via Terminal)* (when available), *Rebase to Commit (via Terminal)* (when available), *Reset to Commit (via Terminal)* (when available), *Create Branch (via Terminal)...*, *Create Tag (via Terminal)...*, and *Refresh* commands
114114
- Context menus for each changed file provide
115115
- *Open Changes*, *Open Changes with Working File*, *Open File*, *Open Revision*, *Open File in Remote*, *Open Revision in Remote*, *Apply Changes*, and *Show Commit File Details* commands
116+
- Inline toolbars for each changed file provide an *Open File* command
116117

117118
- **Remotes** — lists the remotes
118119
- Indicates the direction of the remote (fetch, push, both), remote service (if applicable), and repository path
@@ -147,6 +148,7 @@ The repository view provides a full Git repository explorer, which has the follo
147148
The history view provides the revision history of the active file, which has the following features,
148149
- Automatically updates to track the active editor
149150
- A context menu provides *Open File*, *Open File in Remote* (if available), and *Refresh* commands
151+
- An inline toolbar provides an *Open File* command
150152
- Context menus for each revision (commit) provides
151153
- *Open Changes*, *Open Changes with Working File*, *Open File*, *Open Revision*, *Open File in Remote* (if available), *Open Revision in Remote* (if available), *Apply Changes*, and *Show Commit File Details* commands
152154

@@ -166,6 +168,8 @@ An on-demand, [customizable](#gitlens-results-view-settings "Jump to the GitLens
166168
- *Show Commit Search* command (`gitlens.showCommitSearch`)
167169
- *Show File History* command (`gitlens.showQuickFileHistory`)
168170
- *Show Commit Details* command (`gitlens.showQuickCommitDetails`)
171+
- An inline toolbar provides a *Clear Results* command
172+
- A context menu provides *Clear Results*, and *Refresh* commands
169173
- Revisions (commits) expand show the set of files changed, complete with status indicators for adds, changes, renames, and deletes
170174
- Context menus for each revision (commit) provide
171175
- *Open Commit in Remote* (if available), *Open All Changes*, *Open All Changes with Working Tree*, *Open Files*, *Open Revisions*, *Copy Commit ID to Clipboard*, *Copy Commit Message to Clipboard*, *Show Commit Details*, *Compare with Index (HEAD)*, *Compare with Working Tree*, *Compare with Selected* (when available), *Select for Compare*, *Cherry Pick Commit (via Terminal)* (when available), *Push to Commit (via Terminal)* (when available), *Revert Commit (via Terminal)* (when available), *Rebase to Commit (via Terminal)* (when available), *Reset to Commit (via Terminal)* (when available), *Create Branch (via Terminal)...*, *Create Tag (via Terminal)...*, and *Refresh* commands
@@ -180,7 +184,8 @@ An on-demand, [customizable](#gitlens-results-view-settings "Jump to the GitLens
180184
- *Compare with Working Tree* command (`gitlens.explorers.compareWithWorking`)
181185
- *Compare with Selected* command (`gitlens.explorers.compareWithSelected`)
182186
- *Compare Selected Ancestor with Working Tree* command (`gitlens.explorers.compareSelectedAncestorWithWorking`)
183-
- A context menu provides *Clear Results*, *Open Directory Compare*, and *Refresh* commands
187+
- An inline toolbar provides *Swap Comparision*, and *Clear Results* commands
188+
- A context menu provides *Clear Results*, *Swap Comparision*, *Open Directory Compare*, and *Refresh* commands
184189

185190
- **Commits** — lists the commits between the compared revisions (branches or commits)
186191
- Revisions (commits) expand to show the set of files changed, complete with status indicators for adds, changes, renames, and deletes

images/dark/icon-swap.svg

Lines changed: 3 additions & 0 deletions
Loading

images/light/icon-swap.svg

Lines changed: 3 additions & 0 deletions
Loading

package.json

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,6 +1654,15 @@
16541654
"dark": "images/dark/icon-locked.svg",
16551655
"light": "images/light/icon-locked.svg"
16561656
}
1657+
},
1658+
{
1659+
"command": "gitlens.resultsExplorer.swapComparision",
1660+
"title": "Swap Comparision",
1661+
"category": "GitLens",
1662+
"icon": {
1663+
"dark": "images/dark/icon-swap.svg",
1664+
"light": "images/light/icon-swap.svg"
1665+
}
16571666
}
16581667
],
16591668
"menus": {
@@ -2053,6 +2062,10 @@
20532062
{
20542063
"command": "gitlens.resultsExplorer.setKeepResultsToOff",
20552064
"when": "false"
2065+
},
2066+
{
2067+
"command": "gitlens.resultsExplorer.swapComparision",
2068+
"when": "false"
20562069
}
20572070
],
20582071
"editor/context": [
@@ -2606,16 +2619,26 @@
26062619
"when": "viewItem == gitlens:repository && gitlens:hasRemotes",
26072620
"group": "1_gitlens@1"
26082621
},
2622+
{
2623+
"command": "gitlens.resultsExplorer.swapComparision",
2624+
"when": "viewItem == gitlens:results:comparison",
2625+
"group": "inline@1"
2626+
},
26092627
{
26102628
"command": "gitlens.resultsExplorer.clearResultsNode",
2611-
"when": "viewItem =~ /gitlens:results\\b/",
2612-
"group": "inline"
2629+
"when": "viewItem =~ /gitlens:results\\b(?!:(commits|files))/",
2630+
"group": "inline@2"
26132631
},
26142632
{
26152633
"command": "gitlens.resultsExplorer.clearResultsNode",
2616-
"when": "viewItem =~ /gitlens:results\\b/",
2634+
"when": "viewItem =~ /gitlens:results\\b(?!:(commits|files))/",
26172635
"group": "1_gitlens@1"
26182636
},
2637+
{
2638+
"command": "gitlens.resultsExplorer.swapComparision",
2639+
"when": "viewItem == gitlens:results:comparison",
2640+
"group": "1_gitlens@2"
2641+
},
26192642
{
26202643
"command": "gitlens.explorers.openDirectoryDiff",
26212644
"when": "viewItem == gitlens:results:comparison",

src/views/commitsResultsNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class CommitsResultsNode extends ExplorerNode {
1616
private readonly labelFn: (log: GitLog | undefined) => Promise<string>,
1717
private readonly logFn: (maxCount: number | undefined) => Promise<GitLog | undefined>,
1818
private readonly explorer: Explorer,
19-
private readonly contextValue: ResourceType = ResourceType.Results
19+
private readonly contextValue: ResourceType = ResourceType.ResultsCommits
2020
) {
2121
super(GitUri.fromRepoPath(repoPath));
2222
}

src/views/comparisonResultsNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { StatusFilesResultsNode } from './statusFilesResultsNode';
1111
export class ComparisonResultsNode extends ExplorerNode {
1212

1313
constructor(
14-
repoPath: string,
14+
public readonly repoPath: string,
1515
public readonly ref1: string,
1616
public readonly ref2: string,
1717
private readonly explorer: Explorer

src/views/explorerNode.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ export enum ResourceType {
4141
Repositories = 'gitlens:repositories',
4242
Repository = 'gitlens:repository',
4343
Results = 'gitlens:results',
44+
ResultsCommits = 'gitlens:results:commits',
45+
ResultsFiles = 'gitlens:results:files',
4446
SearchResults = 'gitlens:results:search',
4547
Stash = 'gitlens:stash',
4648
StashFile = 'gitlens:file:stash',

src/views/resultsExplorer.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export class ResultsExplorer extends Disposable implements TreeDataProvider<Expl
3636
commands.registerCommand('gitlens.resultsExplorer.close', this.close, this);
3737
commands.registerCommand('gitlens.resultsExplorer.setKeepResultsToOn', () => this.setKeepResults(true), this);
3838
commands.registerCommand('gitlens.resultsExplorer.setKeepResultsToOff', () => this.setKeepResults(false), this);
39+
commands.registerCommand('gitlens.resultsExplorer.swapComparision', this.swapComparision, this);
3940

4041
setCommandContext(CommandContext.ResultsExplorerKeepResults, this.keepResults);
4142

@@ -216,4 +217,10 @@ export class ResultsExplorer extends Disposable implements TreeDataProvider<Expl
216217
Container.context.workspaceState.update(WorkspaceState.ResultsExplorerKeepResults, enabled);
217218
setCommandContext(CommandContext.ResultsExplorerKeepResults, enabled);
218219
}
220+
221+
private swapComparision(node: ExplorerNode) {
222+
if (!(node instanceof ComparisonResultsNode)) return;
223+
224+
this.showComparisonInResults(node.repoPath, node.ref2, node.ref1);
225+
}
219226
}

src/views/statusFilesResultsNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class StatusFilesResultsNode extends ExplorerNode {
4949
const diff = await this.getDiff();
5050

5151
const item = new TreeItem(await this.getLabel(), diff && diff.length > 0 ? TreeItemCollapsibleState.Expanded : TreeItemCollapsibleState.None);
52-
item.contextValue = ResourceType.Results;
52+
item.contextValue = ResourceType.ResultsFiles;
5353
return item;
5454
}
5555

0 commit comments

Comments
 (0)