Browse Source

Adds open revision command

main
Eric Amodio 5 years ago
parent
commit
7ba6b609f0
6 changed files with 105 additions and 5 deletions
  1. +5
    -0
      images/dark/icon-open-revision.svg
  2. +5
    -0
      images/light/icon-open-revision.svg
  3. +28
    -5
      package.json
  4. +1
    -0
      src/commands.ts
  5. +1
    -0
      src/commands/common.ts
  6. +65
    -0
      src/commands/openRevisionFile.ts

+ 5
- 0
images/dark/icon-open-revision.svg View File

@ -0,0 +1,5 @@
<!--<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none" viewBox="0 0 16 16"> <g fill-rule="evenodd" clip-path="url(#clip0)" clip-rule="evenodd"> <path fill="#C5C5C5" d="M1 2.5l.5-.5h5.7l.3.1 3.4 3.5.1.4v2.44l-.854-.854-.146.146V7H6V3H2v11h6.732l1 1H1.5l-.5-.5v-12zM11 11v1h-1v-1h1zm-1-.44l.854-.853L10.146 9 10 9.146v1.415zm0 3.294l.146.146.708-.707-.854-.854v1.415zM7 3l2.903 3H7V3z"/> <path fill="#75BEFF" d="M10.146 14L8 11.854v-.707L10.146 9l.708.707L9.56 11h3a2.5 2.5 0 0 1 0 5h-.5v-1h.5a1.5 1.5 0 1 0 0-3h-3l1.293 1.293-.708.707z"/> </g> <defs> <clipPath id="clip0"> <path fill="#fff" d="M0 0h16v16H0z"/> </clipPath> </defs> </svg>-->
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none" viewBox="0 0 16 16">
<path fill="#C5C5C5" fill-rule="evenodd" d="M11 6.56l-.854.854L10 7.268V14H2V3h4v4h3.732l-1-1H7V2.732l.565-.565L7.5 2.1 7.2 2H1.5l-.5.5v12l.5.5h9l.5-.5V6.56zm-.274-1.14l-.58.58L8 3.854 10.146 6l.58-.58z" clip-rule="evenodd"/>
<path fill="#75BEFF" fill-rule="evenodd" d="M10.146 6L8 3.854v-.708L10.146 1l.708.707L9.56 3h3a2.5 2.5 0 0 1 0 5h-.5V7h.5a1.5 1.5 0 0 0 0-3h-3l1.293 1.293-.708.707z" clip-rule="evenodd"/>
</svg>

+ 5
- 0
images/light/icon-open-revision.svg View File

@ -0,0 +1,5 @@
<!--<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none" viewBox="0 0 16 16"> <g fill-rule="evenodd" clip-path="url(#clip0)" clip-rule="evenodd"> <path fill="#424242" d="M1 2.5l.5-.5h5.7l.3.1 3.4 3.5.1.4v2.44l-.854-.854-.146.146V7H6V3H2v11h6.732l1 1H1.5l-.5-.5v-12zM11 11v1h-1v-1h1zm-1-.44l.854-.853L10.146 9 10 9.146v1.415zm0 3.294l.146.146.708-.707-.854-.854v1.415zM7 3l2.903 3H7V3z"/> <path fill="#007ACC" d="M10.146 14L8 11.854v-.707L10.146 9l.708.707L9.56 11h3a2.5 2.5 0 0 1 0 5h-.5v-1h.5a1.5 1.5 0 1 0 0-3h-3l1.293 1.293-.708.707z"/> </g> <defs> <clipPath id="clip0"> <path fill="#fff" d="M0 0h16v16H0z"/> </clipPath> </defs> </svg>-->
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none" viewBox="0 0 16 16">
<path fill="#424242" fill-rule="evenodd" d="M11 6.56l-.854.854L10 7.268V14H2V3h4v4h3.732l-1-1H7V2.732l.565-.565L7.5 2.1 7.2 2H1.5l-.5.5v12l.5.5h9l.5-.5V6.56zm-.274-1.14l-.58.58L8 3.854 10.146 6l.58-.58z" clip-rule="evenodd"/>
<path fill="#007ACC" fill-rule="evenodd" d="M10.146 6L8 3.854v-.708L10.146 1l.708.707L9.56 3h3a2.5 2.5 0 0 1 0 5h-.5V7h.5a1.5 1.5 0 0 0 0-3h-3l1.293 1.293-.708.707z" clip-rule="evenodd"/>
</svg>

+ 28
- 5
package.json View File

@ -2304,6 +2304,15 @@
}
},
{
"command": "gitlens.openRevisionFile",
"title": "Open Revision",
"category": "GitLens",
"icon": {
"dark": "images/dark/icon-open-revision.svg",
"light": "images/light/icon-open-revision.svg"
}
},
{
"command": "gitlens.openWorkingFile",
"title": "Open Working File",
"category": "GitLens",
@ -3401,6 +3410,10 @@
"when": "gitlens:hasRemotes"
},
{
"command": "gitlens.openRevisionFile",
"when": "gitlens:activeFileStatus =~ /revision/"
},
{
"command": "gitlens.openWorkingFile",
"when": "gitlens:activeFileStatus =~ /revision/"
},
@ -3948,17 +3961,22 @@
{
"command": "gitlens.openWorkingFile",
"when": "gitlens:activeFileStatus =~ /revision/ && resourceScheme != file && resourceScheme != git",
"group": "navigation@0"
"group": "navigation@1"
},
{
"command": "gitlens.openWorkingFile",
"when": "!gitlens:activeFileStatus =~ /revision/ && resourceScheme != file && resourceScheme != git && isInDiffEditor",
"group": "navigation@0"
"group": "navigation@1"
},
{
"command": "gitlens.openWorkingFile",
"when": "gitlens:activeFileStatus =~ /revision/ && resourceScheme == git && !isInDiffEditor",
"group": "navigation@0"
"group": "navigation@1"
},
{
"command": "gitlens.openRevisionFile",
"when": "gitlens:activeFileStatus =~ /revision/ && isInDiffEditor",
"group": "navigation@2"
},
{
"command": "gitlens.diffWithPrevious",
@ -4006,14 +4024,19 @@
],
"editor/title/context": [
{
"command": "gitlens.openWorkingFile",
"command": "gitlens.openRevisionFile",
"when": "resourceScheme == gitlens",
"group": "1_co_gitlens@1"
},
{
"command": "gitlens.openWorkingFile",
"when": "resourceScheme == gitlens",
"group": "1_co_gitlens@2"
},
{
"command": "gitlens.openFileInRemote",
"when": "gitlens:enabled && gitlens:hasRemotes && config.gitlens.menus.editorTab.remote",
"group": "1_co_gitlens@2"
"group": "1_co_gitlens@3"
},
{
"command": "gitlens.diffWithPrevious",

+ 1
- 0
src/commands.ts View File

@ -27,6 +27,7 @@ export * from './commands/openFileRevision';
export * from './commands/openFileRevisionFrom';
export * from './commands/openInRemote';
export * from './commands/openRepoInRemote';
export * from './commands/openRevisionFile';
export * from './commands/openWorkingFile';
export * from './commands/gitCommands';
export * from './commands/repositories';

+ 1
- 0
src/commands/common.ts View File

@ -65,6 +65,7 @@ export enum Commands {
OpenFileRevisionFromBranch = 'gitlens.openFileRevisionFromBranch',
OpenInRemote = 'gitlens.openInRemote',
OpenRepoInRemote = 'gitlens.openRepoInRemote',
OpenRevisionFile = 'gitlens.openRevisionFile',
OpenWorkingFile = 'gitlens.openWorkingFile',
PullRepositories = 'gitlens.pullRepositories',
PushRepositories = 'gitlens.pushRepositories',

+ 65
- 0
src/commands/openRevisionFile.ts View File

@ -0,0 +1,65 @@
'use strict';
import { Range, TextDocumentShowOptions, TextEditor, Uri } from 'vscode';
import { FileAnnotationType } from '../configuration';
import { Container } from '../container';
import { GitUri } from '../git/gitService';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { ActiveEditorCommand, command, Commands, getCommandUri, openEditor } from './common';
export interface OpenRevisionFileCommandArgs {
uri?: Uri;
line?: number;
showOptions?: TextDocumentShowOptions;
annotationType?: FileAnnotationType;
}
@command()
export class OpenRevisionFileCommand extends ActiveEditorCommand {
constructor() {
super(Commands.OpenRevisionFile);
}
async execute(editor: TextEditor, uri?: Uri, args: OpenRevisionFileCommandArgs = {}) {
args = { ...args };
if (args.line === undefined) {
args.line = editor == null ? 0 : editor.selection.active.line;
}
try {
if (args.uri == null) {
uri = getCommandUri(uri, editor);
if (uri == null) return undefined;
}
else {
uri = args.uri;
}
args.uri = await GitUri.fromUri(uri);
if (GitUri.is(args.uri) && args.uri.sha) {
const commit = await Container.git.getCommit(args.uri.repoPath!, args.uri.sha);
args.uri =
commit !== undefined && commit.status === 'D'
? GitUri.toRevisionUri(commit.previousSha!, commit.previousUri.fsPath, commit.repoPath)
: GitUri.toRevisionUri(args.uri);
}
if (args.line !== undefined && args.line !== 0) {
if (args.showOptions === undefined) {
args.showOptions = {};
}
args.showOptions.selection = new Range(args.line, 0, args.line, 0);
}
const e = await openEditor(args.uri, { ...args.showOptions, rethrow: true });
if (args.annotationType === undefined) return e;
return Container.fileAnnotations.show(e, args.annotationType, args.line);
}
catch (ex) {
Logger.error(ex, 'OpenRevisionFileCommand');
return Messages.showGenericErrorMessage('Unable to open file revision');
}
}
}

Loading…
Cancel
Save