Selaa lähdekoodia

Fixes #776 - Open Rev when in file/line history

main
Eric Amodio 5 vuotta sitten
vanhempi
commit
c5c7254e71
8 muutettua tiedostoa jossa 77 lisäystä ja 84 poistoa
  1. +21
    -5
      package.json
  2. +25
    -43
      src/views/nodes/commitFileNode.ts
  3. +2
    -5
      src/views/nodes/commitNode.ts
  4. +9
    -7
      src/views/nodes/fileHistoryNode.ts
  5. +16
    -7
      src/views/nodes/lineHistoryNode.ts
  6. +2
    -2
      src/views/nodes/stashFileNode.ts
  7. +2
    -14
      src/views/nodes/statusFileNode.ts
  8. +0
    -1
      src/views/nodes/viewNode.ts

+ 21
- 5
package.json Näytä tiedosto

@ -2498,7 +2498,11 @@
{
"command": "gitlens.views.openFileRevision",
"title": "Open Revision",
"category": "GitLens"
"category": "GitLens",
"icon": {
"dark": "images/dark/icon-open-file.svg",
"light": "images/light/icon-open-file.svg"
}
},
{
"command": "gitlens.views.openFileRevisionInRemote",
@ -4401,7 +4405,7 @@
},
{
"command": "gitlens.copyMessageToClipboard",
"when": "viewItem =~ /gitlens:(commit|stash|file:commit)\\b/",
"when": "viewItem =~ /gitlens:(commit|stash|file\\b.*?\\+committed\\b.*?)\\b/",
"group": "5_gitlens@2"
},
{
@ -4446,10 +4450,22 @@
},
{
"command": "gitlens.views.openFile",
"when": "viewItem =~ /gitlens:(file|history:(file|line)|status:file)\\b/",
"when": "viewItem =~ /gitlens:(history:(file|line)|status:file)\\b/",
"group": "inline@1"
},
{
"command": "gitlens.views.openFile",
"when": "viewItem =~ /gitlens:file\\b(?!.*?\\+history\\b.*?)/",
"group": "inline@1",
"alt": "gitlens.views.openFileRevision"
},
{
"command": "gitlens.views.openFileRevision",
"when": "viewItem =~ /gitlens:file\\b.*?\\+history\\b.*?/",
"group": "inline@1",
"alt": "gitlens.views.openFile"
},
{
"command": "gitlens.views.stageFile",
"when": "!gitlens:readonly && viewItem =~ /gitlens:file\\b.*?\\+unstaged\\b.*?/",
"group": "inline@1"
@ -4496,7 +4512,7 @@
},
{
"command": "gitlens.views.openFileRevision",
"when": "viewItem =~ /gitlens:file\\b/",
"when": "viewItem =~ /gitlens:file\\b.*?\\+committed\\b.*?/",
"group": "3_gitlens@2"
},
{
@ -4517,7 +4533,7 @@
},
{
"command": "gitlens.views.openFileRevisionInRemote",
"when": "viewItem == gitlens:file:commit && gitlens:hasRemotes",
"when": "viewItem =~ /gitlens:file\\b.*?\\+committed\\b.*?/ && gitlens:hasRemotes",
"group": "4_gitlens@2"
},
{

+ 25
- 43
src/views/nodes/commitFileNode.ts Näytä tiedosto

@ -8,25 +8,13 @@ import { CommitFormatter, GitFile, GitLogCommit, GitUri, StatusFileFormatter } f
import { View } from '../viewBase';
import { ResourceType, ViewNode, ViewRefFileNode } from './viewNode';
export enum CommitFileNodeDisplayAs {
CommitLabel = 1 << 0,
FileLabel = 1 << 1,
CommitIcon = 1 << 2,
StatusIcon = 1 << 3,
Gravatar = 1 << 4,
File = FileLabel | StatusIcon
}
export class CommitFileNode extends ViewRefFileNode {
constructor(
view: View,
parent: ViewNode,
public readonly file: GitFile,
public commit: GitLogCommit,
private readonly _displayAs: CommitFileNodeDisplayAs,
private readonly _selection?: Selection
private readonly _options: { displayAsCommit?: boolean; inFileHistory?: boolean; selection?: Selection } = {}
) {
super(GitUri.fromFile(file, commit.repoPath, commit.sha), view, parent);
}
@ -70,22 +58,16 @@ export class CommitFileNode extends ViewRefFileNode {
item.description = this.description;
item.tooltip = this.tooltip;
if ((this._displayAs & CommitFileNodeDisplayAs.CommitIcon) === CommitFileNodeDisplayAs.CommitIcon) {
item.iconPath = {
dark: Container.context.asAbsolutePath(paths.join('images', 'dark', 'icon-commit.svg')),
light: Container.context.asAbsolutePath(paths.join('images', 'light', 'icon-commit.svg'))
};
if (this._options.displayAsCommit && this.view.config.avatars) {
item.iconPath = this.commit.getGravatarUri(Container.config.defaultGravatarsStyle);
}
else if ((this._displayAs & CommitFileNodeDisplayAs.StatusIcon) === CommitFileNodeDisplayAs.StatusIcon) {
else {
const icon = GitFile.getStatusIcon(this.file.status);
item.iconPath = {
dark: Container.context.asAbsolutePath(paths.join('images', 'dark', icon)),
light: Container.context.asAbsolutePath(paths.join('images', 'light', icon))
};
}
else if ((this._displayAs & CommitFileNodeDisplayAs.Gravatar) === CommitFileNodeDisplayAs.Gravatar) {
item.iconPath = this.commit.getGravatarUri(Container.config.defaultGravatarsStyle);
}
item.command = this.getCommand();
@ -100,15 +82,14 @@ export class CommitFileNode extends ViewRefFileNode {
private _description: string | undefined;
get description() {
if (this._description === undefined) {
this._description =
this._displayAs & CommitFileNodeDisplayAs.CommitLabel
? CommitFormatter.fromTemplate(this.getCommitDescriptionTemplate(), this.commit, {
truncateMessageAtNewLine: true,
dateFormat: Container.config.defaultDateFormat
})
: StatusFileFormatter.fromTemplate(this.getCommitFileDescriptionTemplate(), this.file, {
relativePath: this.relativePath
});
this._description = this._options.displayAsCommit
? CommitFormatter.fromTemplate(this.getCommitDescriptionTemplate(), this.commit, {
truncateMessageAtNewLine: true,
dateFormat: Container.config.defaultDateFormat
})
: StatusFileFormatter.fromTemplate(this.getCommitFileDescriptionTemplate(), this.file, {
relativePath: this.relativePath
});
}
return this._description;
}
@ -124,15 +105,14 @@ export class CommitFileNode extends ViewRefFileNode {
private _label: string | undefined;
get label() {
if (this._label === undefined) {
this._label =
this._displayAs & CommitFileNodeDisplayAs.CommitLabel
? CommitFormatter.fromTemplate(this.getCommitTemplate(), this.commit, {
truncateMessageAtNewLine: true,
dateFormat: Container.config.defaultDateFormat
})
: StatusFileFormatter.fromTemplate(this.getCommitFileTemplate(), this.file, {
relativePath: this.relativePath
});
this._label = this._options.displayAsCommit
? CommitFormatter.fromTemplate(this.getCommitTemplate(), this.commit, {
truncateMessageAtNewLine: true,
dateFormat: Container.config.defaultDateFormat
})
: StatusFileFormatter.fromTemplate(this.getCommitFileTemplate(), this.file, {
relativePath: this.relativePath
});
}
return this._label;
}
@ -148,7 +128,9 @@ export class CommitFileNode extends ViewRefFileNode {
}
protected get resourceType(): string {
if (!this.commit.isUncommitted) return ResourceType.CommitFile;
if (!this.commit.isUncommitted) {
return `${ResourceType.File}+committed${this._options.inFileHistory ? '+history' : ''}`;
}
return this.commit.isUncommittedStaged ? `${ResourceType.File}+staged` : `${ResourceType.File}+unstaged`;
}
@ -156,7 +138,7 @@ export class CommitFileNode extends ViewRefFileNode {
private _tooltip: string | undefined;
get tooltip() {
if (this._tooltip === undefined) {
if (this._displayAs & CommitFileNodeDisplayAs.CommitLabel) {
if (this._options.displayAsCommit) {
// eslint-disable-next-line no-template-curly-in-string
const status = StatusFileFormatter.fromTemplate('${status}${ (originalPath)}', this.file);
this._tooltip = CommitFormatter.fromTemplate(
@ -208,7 +190,7 @@ export class CommitFileNode extends ViewRefFileNode {
line = this.commit.line.to.line - 1;
}
else {
line = this._selection !== undefined ? this._selection.active.line : 0;
line = this._options.selection !== undefined ? this._options.selection.active.line : 0;
}
const commandArgs: DiffWithPreviousCommandArgs = {

+ 2
- 5
src/views/nodes/commitNode.ts Näytä tiedosto

@ -8,7 +8,7 @@ import { Container } from '../../container';
import { CommitFormatter, GitBranch, GitLogCommit } from '../../git/gitService';
import { Arrays, Iterables, Strings } from '../../system';
import { ViewWithFiles } from '../viewBase';
import { CommitFileNode, CommitFileNodeDisplayAs } from './commitFileNode';
import { CommitFileNode } from './commitFileNode';
import { FileNode, FolderNode } from './folderNode';
import { ResourceType, ViewNode, ViewRefNode } from './viewNode';
@ -30,10 +30,7 @@ export class CommitNode extends ViewRefNode {
async getChildren(): Promise<ViewNode[]> {
const commit = this.commit;
let children: FileNode[] = [
...Iterables.map(
commit.files,
s => new CommitFileNode(this.view, this, s, commit.toFileCommit(s), CommitFileNodeDisplayAs.File)
)
...Iterables.map(commit.files, s => new CommitFileNode(this.view, this, s, commit.toFileCommit(s)))
];
if (this.view.config.files.layout !== ViewFilesLayout.List) {

+ 9
- 7
src/views/nodes/fileHistoryNode.ts Näytä tiedosto

@ -13,7 +13,7 @@ import {
import { Logger } from '../../logger';
import { debug, Iterables } from '../../system';
import { View } from '../viewBase';
import { CommitFileNode, CommitFileNodeDisplayAs } from './commitFileNode';
import { CommitFileNode } from './commitFileNode';
import { MessageNode, ShowMoreNode } from './common';
import { insertDateMarkers } from './helpers';
import { PageableViewNode, ResourceType, SubscribeableViewNode, ViewNode } from './viewNode';
@ -29,10 +29,6 @@ export class FileHistoryNode extends SubscribeableViewNode implements PageableVi
async getChildren(): Promise<ViewNode[]> {
const children: ViewNode[] = [];
const displayAs =
CommitFileNodeDisplayAs.CommitLabel |
(this.view.config.avatars ? CommitFileNodeDisplayAs.Gravatar : CommitFileNodeDisplayAs.StatusIcon);
if (this.uri.sha === undefined) {
const status = await Container.git.getStatusForFile(this.uri.repoPath!, this.uri.fsPath);
if (status !== undefined && (status.indexStatus !== undefined || status.workingTreeStatus !== undefined)) {
@ -69,7 +65,9 @@ export class FileHistoryNode extends SubscribeableViewNode implements PageableVi
previousSha,
status.originalFileName || status.fileName
);
children.push(new CommitFileNode(this.view, this, status, commit, displayAs));
children.push(
new CommitFileNode(this.view, this, status, commit, { displayAsCommit: true, inFileHistory: true })
);
}
}
@ -82,7 +80,11 @@ export class FileHistoryNode extends SubscribeableViewNode implements PageableVi
...insertDateMarkers(
Iterables.map(
log.commits.values(),
c => new CommitFileNode(this.view, this, c.files[0], c, displayAs)
c =>
new CommitFileNode(this.view, this, c.files[0], c, {
displayAsCommit: true,
inFileHistory: true
})
),
this
)

+ 16
- 7
src/views/nodes/lineHistoryNode.ts Näytä tiedosto

@ -12,7 +12,7 @@ import {
import { Logger } from '../../logger';
import { debug, Iterables } from '../../system';
import { View } from '../viewBase';
import { CommitFileNode, CommitFileNodeDisplayAs } from './commitFileNode';
import { CommitFileNode } from './commitFileNode';
import { MessageNode, ShowMoreNode } from './common';
import { insertDateMarkers } from './helpers';
import { PageableViewNode, ResourceType, SubscribeableViewNode, ViewNode } from './viewNode';
@ -34,10 +34,6 @@ export class LineHistoryNode extends SubscribeableViewNode implements PageableVi
async getChildren(): Promise<ViewNode[]> {
const children: ViewNode[] = [];
const displayAs =
CommitFileNodeDisplayAs.CommitLabel |
(this.view.config.avatars ? CommitFileNodeDisplayAs.Gravatar : CommitFileNodeDisplayAs.StatusIcon);
let selection = this.selection;
if (this.uri.sha === undefined) {
@ -87,7 +83,15 @@ export class LineHistoryNode extends SubscribeableViewNode implements PageableVi
selection.active.character
);
children.splice(0, 0, new CommitFileNode(this.view, this, file, uncommitted, displayAs, selection));
children.splice(
0,
0,
new CommitFileNode(this.view, this, file, uncommitted, {
displayAsCommit: true,
inFileHistory: true,
selection: selection
})
);
break;
}
@ -104,7 +108,12 @@ export class LineHistoryNode extends SubscribeableViewNode implements PageableVi
...insertDateMarkers(
Iterables.filterMap(
log.commits.values(),
c => new CommitFileNode(this.view, this, c.files[0], c, displayAs, selection)
c =>
new CommitFileNode(this.view, this, c.files[0], c, {
displayAsCommit: true,
inFileHistory: true,
selection: selection
})
),
this
)

+ 2
- 2
src/views/nodes/stashFileNode.ts Näytä tiedosto

@ -1,12 +1,12 @@
'use strict';
import { GitFile, GitLogCommit } from '../../git/gitService';
import { View } from '../viewBase';
import { CommitFileNode, CommitFileNodeDisplayAs } from './commitFileNode';
import { CommitFileNode } from './commitFileNode';
import { ResourceType, ViewNode } from './viewNode';
export class StashFileNode extends CommitFileNode {
constructor(view: View, parent: ViewNode, file: GitFile, commit: GitLogCommit) {
super(view, parent, file, commit, CommitFileNodeDisplayAs.File);
super(view, parent, file, commit);
}
protected get resourceType(): ResourceType {

+ 2
- 14
src/views/nodes/statusFileNode.ts Näytä tiedosto

@ -6,7 +6,7 @@ import { Container } from '../../container';
import { GitFile, GitLogCommit, GitUri, StatusFileFormatter } from '../../git/gitService';
import { Strings } from '../../system';
import { View } from '../viewBase';
import { CommitFileNode, CommitFileNodeDisplayAs } from './commitFileNode';
import { CommitFileNode } from './commitFileNode';
import { ResourceType, ViewNode } from './viewNode';
export class StatusFileNode extends ViewNode {
@ -56,19 +56,7 @@ export class StatusFileNode extends ViewNode {
}
getChildren(): ViewNode[] {
return this.commits.map(
c =>
new CommitFileNode(
this.view,
this,
this.file,
c,
CommitFileNodeDisplayAs.CommitLabel |
(this.view.config.avatars
? CommitFileNodeDisplayAs.Gravatar
: CommitFileNodeDisplayAs.CommitIcon)
)
);
return this.commits.map(c => new CommitFileNode(this.view, this, this.file, c, { displayAsCommit: true }));
}
getTreeItem(): TreeItem {

+ 0
- 1
src/views/nodes/viewNode.ts Näytä tiedosto

@ -13,7 +13,6 @@ export enum ResourceType {
BranchStatusAheadOfUpstream = 'gitlens:branch-status:upstream:ahead',
BranchStatusBehindUpstream = 'gitlens:branch-status:upstream:behind',
Commit = 'gitlens:commit',
CommitFile = 'gitlens:file:commit',
Commits = 'gitlens:commits',
Compare = 'gitlens:compare',
CompareBranch = 'gitlens:compare:branch',

Ladataan…
Peruuta
Tallenna