Browse Source

Adds copy context menu entry to many nodes

Renames Copy Commit ID to Copy SHA
Renames Copy Commit Message to Copy Message
main
Eric Amodio 4 years ago
parent
commit
5049a6e105
6 changed files with 43 additions and 42 deletions
  1. +20
    -24
      package.json
  2. +0
    -4
      src/commands/gitCommands.actions.ts
  3. +11
    -1
      src/views/nodes/commitFileNode.ts
  4. +7
    -1
      src/views/nodes/commitNode.ts
  5. +1
    -1
      src/views/nodes/contributorNode.ts
  6. +4
    -11
      src/views/viewCommands.ts

+ 20
- 24
package.json View File

@ -2913,7 +2913,7 @@
},
{
"command": "gitlens.copyMessageToClipboard",
"title": "Copy Commit Message",
"title": "Copy Message",
"category": "GitLens",
"icon": {
"dark": "images/dark/icon-copy-message.svg",
@ -2940,7 +2940,7 @@
},
{
"command": "gitlens.copyShaToClipboard",
"title": "Copy Commit ID",
"title": "Copy SHA",
"category": "GitLens",
"icon": {
"dark": "images/dark/icon-copy.svg",
@ -3259,7 +3259,11 @@
{
"command": "gitlens.views.copy",
"title": "Copy",
"category": "GitLens"
"category": "GitLens",
"icon": {
"dark": "images/dark/icon-copy.svg",
"light": "images/light/icon-copy.svg"
}
},
{
"command": "gitlens.views.pruneRemote",
@ -3493,15 +3497,6 @@
}
},
{
"command": "gitlens.views.copyContributorToClipboard",
"title": "Copy",
"category": "GitLens",
"icon": {
"dark": "images/dark/icon-copy.svg",
"light": "images/light/icon-copy.svg"
}
},
{
"command": "gitlens.views.cherryPick",
"title": "Cherry Pick Commit...",
"category": "GitLens"
@ -4897,10 +4892,6 @@
"when": "false"
},
{
"command": "gitlens.views.copyContributorToClipboard",
"when": "false"
},
{
"command": "gitlens.views.createBranch",
"when": "false"
},
@ -6635,7 +6626,7 @@
"group": "inline@2"
},
{
"command": "gitlens.views.copyContributorToClipboard",
"command": "gitlens.views.copy",
"when": "viewItem =~ /gitlens:contributor\\b/",
"group": "inline@98"
},
@ -6650,11 +6641,6 @@
"group": "1_gitlens_actions@2"
},
{
"command": "gitlens.views.copyContributorToClipboard",
"when": "viewItem =~ /gitlens:contributor\\b/",
"group": "7_gitlens_cutcopypaste@1"
},
{
"command": "gitlens.copyShaToClipboard",
"when": "viewItem =~ /gitlens:commit\\b/",
"group": "inline@98",
@ -6755,12 +6741,12 @@
{
"command": "gitlens.copyShaToClipboard",
"when": "viewItem =~ /gitlens:(commit|file\\b(?=.*?\\b\\+committed\\b))\\b/",
"group": "7_gitlens_cutcopypaste@1"
"group": "7_gitlens_cutcopypaste@2"
},
{
"command": "gitlens.copyMessageToClipboard",
"when": "viewItem =~ /gitlens:(commit|stash|file\\b(?=.*?\\b\\+committed\\b))\\b/",
"group": "7_gitlens_cutcopypaste@2"
"group": "7_gitlens_cutcopypaste@3"
},
{
"command": "gitlens.views.openFile",
@ -7337,6 +7323,16 @@
"group": "1_gitlens_actions@2"
},
{
"command": "gitlens.views.copy",
"when": "viewItem =~ /gitlens:(?=(branch|commit|contributor|folder|history:line|pullrequest|remote|repository|stash|tag)\\b)/",
"group": "7_gitlens_cutcopypaste@1"
},
{
"command": "gitlens.views.copy",
"when": "viewItem =~ /gitlens:file(?!.*?\\b\\+(staged|unstaged))\\b/",
"group": "7_gitlens_cutcopypaste@1"
},
{
"command": "gitlens.views.dismissNode",
"when": "viewItem =~ /gitlens:(compare:picker:ref|compare:results\\b(?!.*?\\b\\+pinned\\b)|search)\\b(?!:(commits|files))/",
"group": "8_gitlens_actions@98"

+ 0
- 4
src/commands/gitCommands.actions.ts View File

@ -711,10 +711,6 @@ export namespace GitActions {
state: { repo: repo, contributors: contributors },
});
}
export async function copyToClipboard(contributor: GitContributor) {
await env.clipboard.writeText(`${contributor.name}${contributor.email ? ` <${contributor.email}>` : ''}`);
}
}
export namespace Tag {

+ 11
- 1
src/views/nodes/commitFileNode.ts View File

@ -22,7 +22,17 @@ export class CommitFileNode extends ViewRefFileNode {
}
toClipboard(): string {
return this._options.displayAsCommit ? this.commit.sha : this.fileName;
if (this._options.displayAsCommit) {
let message = this.commit.message;
const index = message.indexOf('\n');
if (index !== -1) {
message = `${message.substring(0, index)}${GlyphChars.Space}${GlyphChars.Ellipsis}`;
}
return `${this.commit.shortSha}: ${message}`;
}
return this.fileName;
}
get fileName(): string {

+ 7
- 1
src/views/nodes/commitNode.ts View File

@ -29,7 +29,13 @@ export class CommitNode extends ViewRefNode
}
toClipboard(): string {
return this.commit.sha;
let message = this.commit.message;
const index = message.indexOf('\n');
if (index !== -1) {
message = `${message.substring(0, index)}${GlyphChars.Space}${GlyphChars.Ellipsis}`;
}
return `${this.commit.shortSha}: ${message}`;
}
get ref(): GitRevisionReference {

+ 1
- 1
src/views/nodes/contributorNode.ts View File

@ -31,7 +31,7 @@ export class ContributorNode extends ViewNode
}
toClipboard(): string {
return this.contributor.name;
return `${this.contributor.name}${this.contributor.email ? ` <${this.contributor.email}>` : ''}`;
}
get id(): string {

+ 4
- 11
src/views/viewCommands.ts View File

@ -56,12 +56,13 @@ export class ViewCommands {
constructor() {
commands.registerCommand(
'gitlens.views.copy',
async (selection: ViewNode[]) => {
async (selection: ViewNode | ViewNode[]) => {
selection = Array.isArray(selection) ? selection : [selection];
if (selection.length === 0) return;
const data = selection
.filter(n => n.toClipboard != null)
.map(n => n.toClipboard!())
.map(n => n.toClipboard?.())
.filter(s => s != null && s.length > 0)
.join(',');
await env.clipboard.writeText(data);
},
@ -132,7 +133,6 @@ export class ViewCommands {
commands.registerCommand('gitlens.views.addAuthors', this.addAuthors, this);
commands.registerCommand('gitlens.views.addAuthor', this.addAuthors, this);
commands.registerCommand('gitlens.views.copyContributorToClipboard', this.copyContributorToClipboard, this);
commands.registerCommand('gitlens.views.openChanges', this.openChanges, this);
commands.registerCommand('gitlens.views.openChangesWithWorking', this.openChangesWithWorking, this);
@ -253,13 +253,6 @@ export class ViewCommands {
}
@debug()
private copyContributorToClipboard(node: ContributorNode) {
if (!(node instanceof ContributorNode)) return Promise.resolve();
return GitActions.Contributor.copyToClipboard(node.contributor);
}
@debug()
private createBranch(node?: ViewRefNode) {
if (node != null && !(node instanceof ViewRefNode)) return Promise.resolve();

Loading…
Cancel
Save