Skip to content

Commit c5c7254

Browse files
committed
Fixes #776 - Open Rev when in file/line history
1 parent a642958 commit c5c7254

File tree

8 files changed

+77
-84
lines changed

8 files changed

+77
-84
lines changed

package.json

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2498,7 +2498,11 @@
24982498
{
24992499
"command": "gitlens.views.openFileRevision",
25002500
"title": "Open Revision",
2501-
"category": "GitLens"
2501+
"category": "GitLens",
2502+
"icon": {
2503+
"dark": "images/dark/icon-open-file.svg",
2504+
"light": "images/light/icon-open-file.svg"
2505+
}
25022506
},
25032507
{
25042508
"command": "gitlens.views.openFileRevisionInRemote",
@@ -4401,7 +4405,7 @@
44014405
},
44024406
{
44034407
"command": "gitlens.copyMessageToClipboard",
4404-
"when": "viewItem =~ /gitlens:(commit|stash|file:commit)\\b/",
4408+
"when": "viewItem =~ /gitlens:(commit|stash|file\\b.*?\\+committed\\b.*?)\\b/",
44054409
"group": "5_gitlens@2"
44064410
},
44074411
{
@@ -4446,9 +4450,21 @@
44464450
},
44474451
{
44484452
"command": "gitlens.views.openFile",
4449-
"when": "viewItem =~ /gitlens:(file|history:(file|line)|status:file)\\b/",
4453+
"when": "viewItem =~ /gitlens:(history:(file|line)|status:file)\\b/",
44504454
"group": "inline@1"
44514455
},
4456+
{
4457+
"command": "gitlens.views.openFile",
4458+
"when": "viewItem =~ /gitlens:file\\b(?!.*?\\+history\\b.*?)/",
4459+
"group": "inline@1",
4460+
"alt": "gitlens.views.openFileRevision"
4461+
},
4462+
{
4463+
"command": "gitlens.views.openFileRevision",
4464+
"when": "viewItem =~ /gitlens:file\\b.*?\\+history\\b.*?/",
4465+
"group": "inline@1",
4466+
"alt": "gitlens.views.openFile"
4467+
},
44524468
{
44534469
"command": "gitlens.views.stageFile",
44544470
"when": "!gitlens:readonly && viewItem =~ /gitlens:file\\b.*?\\+unstaged\\b.*?/",
@@ -4496,7 +4512,7 @@
44964512
},
44974513
{
44984514
"command": "gitlens.views.openFileRevision",
4499-
"when": "viewItem =~ /gitlens:file\\b/",
4515+
"when": "viewItem =~ /gitlens:file\\b.*?\\+committed\\b.*?/",
45004516
"group": "3_gitlens@2"
45014517
},
45024518
{
@@ -4517,7 +4533,7 @@
45174533
},
45184534
{
45194535
"command": "gitlens.views.openFileRevisionInRemote",
4520-
"when": "viewItem == gitlens:file:commit && gitlens:hasRemotes",
4536+
"when": "viewItem =~ /gitlens:file\\b.*?\\+committed\\b.*?/ && gitlens:hasRemotes",
45214537
"group": "4_gitlens@2"
45224538
},
45234539
{

src/views/nodes/commitFileNode.ts

Lines changed: 25 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,13 @@ import { CommitFormatter, GitFile, GitLogCommit, GitUri, StatusFileFormatter } f
88
import { View } from '../viewBase';
99
import { ResourceType, ViewNode, ViewRefFileNode } from './viewNode';
1010

11-
export enum CommitFileNodeDisplayAs {
12-
CommitLabel = 1 << 0,
13-
FileLabel = 1 << 1,
14-
15-
CommitIcon = 1 << 2,
16-
StatusIcon = 1 << 3,
17-
Gravatar = 1 << 4,
18-
19-
File = FileLabel | StatusIcon
20-
}
21-
2211
export class CommitFileNode extends ViewRefFileNode {
2312
constructor(
2413
view: View,
2514
parent: ViewNode,
2615
public readonly file: GitFile,
2716
public commit: GitLogCommit,
28-
private readonly _displayAs: CommitFileNodeDisplayAs,
29-
private readonly _selection?: Selection
17+
private readonly _options: { displayAsCommit?: boolean; inFileHistory?: boolean; selection?: Selection } = {}
3018
) {
3119
super(GitUri.fromFile(file, commit.repoPath, commit.sha), view, parent);
3220
}
@@ -70,22 +58,16 @@ export class CommitFileNode extends ViewRefFileNode {
7058
item.description = this.description;
7159
item.tooltip = this.tooltip;
7260

73-
if ((this._displayAs & CommitFileNodeDisplayAs.CommitIcon) === CommitFileNodeDisplayAs.CommitIcon) {
74-
item.iconPath = {
75-
dark: Container.context.asAbsolutePath(paths.join('images', 'dark', 'icon-commit.svg')),
76-
light: Container.context.asAbsolutePath(paths.join('images', 'light', 'icon-commit.svg'))
77-
};
61+
if (this._options.displayAsCommit && this.view.config.avatars) {
62+
item.iconPath = this.commit.getGravatarUri(Container.config.defaultGravatarsStyle);
7863
}
79-
else if ((this._displayAs & CommitFileNodeDisplayAs.StatusIcon) === CommitFileNodeDisplayAs.StatusIcon) {
64+
else {
8065
const icon = GitFile.getStatusIcon(this.file.status);
8166
item.iconPath = {
8267
dark: Container.context.asAbsolutePath(paths.join('images', 'dark', icon)),
8368
light: Container.context.asAbsolutePath(paths.join('images', 'light', icon))
8469
};
8570
}
86-
else if ((this._displayAs & CommitFileNodeDisplayAs.Gravatar) === CommitFileNodeDisplayAs.Gravatar) {
87-
item.iconPath = this.commit.getGravatarUri(Container.config.defaultGravatarsStyle);
88-
}
8971

9072
item.command = this.getCommand();
9173

@@ -100,15 +82,14 @@ export class CommitFileNode extends ViewRefFileNode {
10082
private _description: string | undefined;
10183
get description() {
10284
if (this._description === undefined) {
103-
this._description =
104-
this._displayAs & CommitFileNodeDisplayAs.CommitLabel
105-
? CommitFormatter.fromTemplate(this.getCommitDescriptionTemplate(), this.commit, {
106-
truncateMessageAtNewLine: true,
107-
dateFormat: Container.config.defaultDateFormat
108-
})
109-
: StatusFileFormatter.fromTemplate(this.getCommitFileDescriptionTemplate(), this.file, {
110-
relativePath: this.relativePath
111-
});
85+
this._description = this._options.displayAsCommit
86+
? CommitFormatter.fromTemplate(this.getCommitDescriptionTemplate(), this.commit, {
87+
truncateMessageAtNewLine: true,
88+
dateFormat: Container.config.defaultDateFormat
89+
})
90+
: StatusFileFormatter.fromTemplate(this.getCommitFileDescriptionTemplate(), this.file, {
91+
relativePath: this.relativePath
92+
});
11293
}
11394
return this._description;
11495
}
@@ -124,15 +105,14 @@ export class CommitFileNode extends ViewRefFileNode {
124105
private _label: string | undefined;
125106
get label() {
126107
if (this._label === undefined) {
127-
this._label =
128-
this._displayAs & CommitFileNodeDisplayAs.CommitLabel
129-
? CommitFormatter.fromTemplate(this.getCommitTemplate(), this.commit, {
130-
truncateMessageAtNewLine: true,
131-
dateFormat: Container.config.defaultDateFormat
132-
})
133-
: StatusFileFormatter.fromTemplate(this.getCommitFileTemplate(), this.file, {
134-
relativePath: this.relativePath
135-
});
108+
this._label = this._options.displayAsCommit
109+
? CommitFormatter.fromTemplate(this.getCommitTemplate(), this.commit, {
110+
truncateMessageAtNewLine: true,
111+
dateFormat: Container.config.defaultDateFormat
112+
})
113+
: StatusFileFormatter.fromTemplate(this.getCommitFileTemplate(), this.file, {
114+
relativePath: this.relativePath
115+
});
136116
}
137117
return this._label;
138118
}
@@ -148,15 +128,17 @@ export class CommitFileNode extends ViewRefFileNode {
148128
}
149129

150130
protected get resourceType(): string {
151-
if (!this.commit.isUncommitted) return ResourceType.CommitFile;
131+
if (!this.commit.isUncommitted) {
132+
return `${ResourceType.File}+committed${this._options.inFileHistory ? '+history' : ''}`;
133+
}
152134

153135
return this.commit.isUncommittedStaged ? `${ResourceType.File}+staged` : `${ResourceType.File}+unstaged`;
154136
}
155137

156138
private _tooltip: string | undefined;
157139
get tooltip() {
158140
if (this._tooltip === undefined) {
159-
if (this._displayAs & CommitFileNodeDisplayAs.CommitLabel) {
141+
if (this._options.displayAsCommit) {
160142
// eslint-disable-next-line no-template-curly-in-string
161143
const status = StatusFileFormatter.fromTemplate('${status}${ (originalPath)}', this.file);
162144
this._tooltip = CommitFormatter.fromTemplate(
@@ -208,7 +190,7 @@ export class CommitFileNode extends ViewRefFileNode {
208190
line = this.commit.line.to.line - 1;
209191
}
210192
else {
211-
line = this._selection !== undefined ? this._selection.active.line : 0;
193+
line = this._options.selection !== undefined ? this._options.selection.active.line : 0;
212194
}
213195

214196
const commandArgs: DiffWithPreviousCommandArgs = {

src/views/nodes/commitNode.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Container } from '../../container';
88
import { CommitFormatter, GitBranch, GitLogCommit } from '../../git/gitService';
99
import { Arrays, Iterables, Strings } from '../../system';
1010
import { ViewWithFiles } from '../viewBase';
11-
import { CommitFileNode, CommitFileNodeDisplayAs } from './commitFileNode';
11+
import { CommitFileNode } from './commitFileNode';
1212
import { FileNode, FolderNode } from './folderNode';
1313
import { ResourceType, ViewNode, ViewRefNode } from './viewNode';
1414

@@ -30,10 +30,7 @@ export class CommitNode extends ViewRefNode<ViewWithFiles> {
3030
async getChildren(): Promise<ViewNode[]> {
3131
const commit = this.commit;
3232
let children: FileNode[] = [
33-
...Iterables.map(
34-
commit.files,
35-
s => new CommitFileNode(this.view, this, s, commit.toFileCommit(s), CommitFileNodeDisplayAs.File)
36-
)
33+
...Iterables.map(commit.files, s => new CommitFileNode(this.view, this, s, commit.toFileCommit(s)))
3734
];
3835

3936
if (this.view.config.files.layout !== ViewFilesLayout.List) {

src/views/nodes/fileHistoryNode.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
import { Logger } from '../../logger';
1414
import { debug, Iterables } from '../../system';
1515
import { View } from '../viewBase';
16-
import { CommitFileNode, CommitFileNodeDisplayAs } from './commitFileNode';
16+
import { CommitFileNode } from './commitFileNode';
1717
import { MessageNode, ShowMoreNode } from './common';
1818
import { insertDateMarkers } from './helpers';
1919
import { PageableViewNode, ResourceType, SubscribeableViewNode, ViewNode } from './viewNode';
@@ -29,10 +29,6 @@ export class FileHistoryNode extends SubscribeableViewNode implements PageableVi
2929
async getChildren(): Promise<ViewNode[]> {
3030
const children: ViewNode[] = [];
3131

32-
const displayAs =
33-
CommitFileNodeDisplayAs.CommitLabel |
34-
(this.view.config.avatars ? CommitFileNodeDisplayAs.Gravatar : CommitFileNodeDisplayAs.StatusIcon);
35-
3632
if (this.uri.sha === undefined) {
3733
const status = await Container.git.getStatusForFile(this.uri.repoPath!, this.uri.fsPath);
3834
if (status !== undefined && (status.indexStatus !== undefined || status.workingTreeStatus !== undefined)) {
@@ -69,7 +65,9 @@ export class FileHistoryNode extends SubscribeableViewNode implements PageableVi
6965
previousSha,
7066
status.originalFileName || status.fileName
7167
);
72-
children.push(new CommitFileNode(this.view, this, status, commit, displayAs));
68+
children.push(
69+
new CommitFileNode(this.view, this, status, commit, { displayAsCommit: true, inFileHistory: true })
70+
);
7371
}
7472
}
7573

@@ -82,7 +80,11 @@ export class FileHistoryNode extends SubscribeableViewNode implements PageableVi
8280
...insertDateMarkers(
8381
Iterables.map(
8482
log.commits.values(),
85-
c => new CommitFileNode(this.view, this, c.files[0], c, displayAs)
83+
c =>
84+
new CommitFileNode(this.view, this, c.files[0], c, {
85+
displayAsCommit: true,
86+
inFileHistory: true
87+
})
8688
),
8789
this
8890
)

src/views/nodes/lineHistoryNode.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
import { Logger } from '../../logger';
1313
import { debug, Iterables } from '../../system';
1414
import { View } from '../viewBase';
15-
import { CommitFileNode, CommitFileNodeDisplayAs } from './commitFileNode';
15+
import { CommitFileNode } from './commitFileNode';
1616
import { MessageNode, ShowMoreNode } from './common';
1717
import { insertDateMarkers } from './helpers';
1818
import { PageableViewNode, ResourceType, SubscribeableViewNode, ViewNode } from './viewNode';
@@ -34,10 +34,6 @@ export class LineHistoryNode extends SubscribeableViewNode implements PageableVi
3434
async getChildren(): Promise<ViewNode[]> {
3535
const children: ViewNode[] = [];
3636

37-
const displayAs =
38-
CommitFileNodeDisplayAs.CommitLabel |
39-
(this.view.config.avatars ? CommitFileNodeDisplayAs.Gravatar : CommitFileNodeDisplayAs.StatusIcon);
40-
4137
let selection = this.selection;
4238

4339
if (this.uri.sha === undefined) {
@@ -87,7 +83,15 @@ export class LineHistoryNode extends SubscribeableViewNode implements PageableVi
8783
selection.active.character
8884
);
8985

90-
children.splice(0, 0, new CommitFileNode(this.view, this, file, uncommitted, displayAs, selection));
86+
children.splice(
87+
0,
88+
0,
89+
new CommitFileNode(this.view, this, file, uncommitted, {
90+
displayAsCommit: true,
91+
inFileHistory: true,
92+
selection: selection
93+
})
94+
);
9195

9296
break;
9397
}
@@ -104,7 +108,12 @@ export class LineHistoryNode extends SubscribeableViewNode implements PageableVi
104108
...insertDateMarkers(
105109
Iterables.filterMap(
106110
log.commits.values(),
107-
c => new CommitFileNode(this.view, this, c.files[0], c, displayAs, selection)
111+
c =>
112+
new CommitFileNode(this.view, this, c.files[0], c, {
113+
displayAsCommit: true,
114+
inFileHistory: true,
115+
selection: selection
116+
})
108117
),
109118
this
110119
)

src/views/nodes/stashFileNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
'use strict';
22
import { GitFile, GitLogCommit } from '../../git/gitService';
33
import { View } from '../viewBase';
4-
import { CommitFileNode, CommitFileNodeDisplayAs } from './commitFileNode';
4+
import { CommitFileNode } from './commitFileNode';
55
import { ResourceType, ViewNode } from './viewNode';
66

77
export class StashFileNode extends CommitFileNode {
88
constructor(view: View, parent: ViewNode, file: GitFile, commit: GitLogCommit) {
9-
super(view, parent, file, commit, CommitFileNodeDisplayAs.File);
9+
super(view, parent, file, commit);
1010
}
1111

1212
protected get resourceType(): ResourceType {

src/views/nodes/statusFileNode.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Container } from '../../container';
66
import { GitFile, GitLogCommit, GitUri, StatusFileFormatter } from '../../git/gitService';
77
import { Strings } from '../../system';
88
import { View } from '../viewBase';
9-
import { CommitFileNode, CommitFileNodeDisplayAs } from './commitFileNode';
9+
import { CommitFileNode } from './commitFileNode';
1010
import { ResourceType, ViewNode } from './viewNode';
1111

1212
export class StatusFileNode extends ViewNode {
@@ -56,19 +56,7 @@ export class StatusFileNode extends ViewNode {
5656
}
5757

5858
getChildren(): ViewNode[] {
59-
return this.commits.map(
60-
c =>
61-
new CommitFileNode(
62-
this.view,
63-
this,
64-
this.file,
65-
c,
66-
CommitFileNodeDisplayAs.CommitLabel |
67-
(this.view.config.avatars
68-
? CommitFileNodeDisplayAs.Gravatar
69-
: CommitFileNodeDisplayAs.CommitIcon)
70-
)
71-
);
59+
return this.commits.map(c => new CommitFileNode(this.view, this, this.file, c, { displayAsCommit: true }));
7260
}
7361

7462
getTreeItem(): TreeItem {

src/views/nodes/viewNode.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export enum ResourceType {
1313
BranchStatusAheadOfUpstream = 'gitlens:branch-status:upstream:ahead',
1414
BranchStatusBehindUpstream = 'gitlens:branch-status:upstream:behind',
1515
Commit = 'gitlens:commit',
16-
CommitFile = 'gitlens:file:commit',
1716
Commits = 'gitlens:commits',
1817
Compare = 'gitlens:compare',
1918
CompareBranch = 'gitlens:compare:branch',

0 commit comments

Comments
 (0)