Przeglądaj źródła

Fixes #1411 - stops click edit on compare node

Adds explicit edit action when there is a comparison
main
Eric Amodio 3 lat temu
rodzic
commit
5770d59310
5 zmienionych plików z 78 dodań i 70 usunięć
  1. +22
    -12
      package.json
  2. +14
    -7
      src/views/nodes/compareBranchNode.ts
  3. +13
    -12
      src/views/nodes/viewNode.ts
  4. +0
    -7
      src/views/searchAndCompareView.ts
  5. +29
    -32
      src/views/viewCommands.ts

+ 22
- 12
package.json Wyświetl plik

@ -4257,6 +4257,12 @@
"icon": "$(close)"
},
{
"command": "gitlens.views.editNode",
"title": "Edit...",
"category": "GitLens",
"icon": "$(edit)"
},
{
"command": "gitlens.views.expandNode",
"title": "Expand",
"category": "GitLens"
@ -4852,12 +4858,6 @@
"icon": "$(search)"
},
{
"command": "gitlens.views.searchAndCompare.edit",
"title": "Edit...",
"category": "GitLens",
"icon": "$(edit)"
},
{
"command": "gitlens.views.searchAndCompare.selectForCompare",
"title": "Compare References...",
"category": "GitLens",
@ -5809,6 +5809,10 @@
"when": "false"
},
{
"command": "gitlens.views.editNode",
"when": "false"
},
{
"command": "gitlens.views.expandNode",
"when": "false"
},
@ -6233,10 +6237,6 @@
"when": "false"
},
{
"command": "gitlens.views.searchAndCompare.edit",
"when": "false"
},
{
"command": "gitlens.views.searchAndCompare.selectForCompare",
"when": "false"
},
@ -8111,6 +8111,11 @@
"group": "inline@99"
},
{
"command": "gitlens.views.editNode",
"when": "viewItem =~ /gitlens:compare:branch\\b(?=.*?\\b\\+comparing\\b)/",
"group": "inline@98"
},
{
"command": "gitlens.views.setBranchComparisonToWorking",
"when": "viewItem =~ /gitlens:compare:branch\\b(?=.*?\\b\\+root\\b)(?=.*?\\b\\+current\\b)(?=.*?\\b\\+branch\\b)/",
"group": "inline@2"
@ -8121,6 +8126,11 @@
"group": "inline@2"
},
{
"command": "gitlens.views.editNode",
"when": "viewItem =~ /gitlens:compare:branch\\b(?=.*?\\b\\+comparing\\b)/",
"group": "1_gitlens@1"
},
{
"command": "gitlens.views.setBranchComparisonToWorking",
"when": "viewItem =~ /gitlens:compare:branch\\b(?=.*?\\b\\+root\\b)(?=.*?\\b\\+current\\b)(?=.*?\\b\\+branch\\b)/",
"group": "1_gitlens@2"
@ -8201,12 +8211,12 @@
"group": "8_gitlens_actions@1"
},
{
"command": "gitlens.views.searchAndCompare.edit",
"command": "gitlens.views.editNode",
"when": "viewItem =~ /gitlens:search:results(?!:)\\b/",
"group": "inline@1"
},
{
"command": "gitlens.views.searchAndCompare.edit",
"command": "gitlens.views.editNode",
"when": "viewItem =~ /gitlens:search:results(?!:)\\b/",
"group": "1_gitlens_actions@1"
},

+ 14
- 7
src/views/nodes/compareBranchNode.ts Wyświetl plik

@ -154,13 +154,15 @@ export class CompareBranchNode extends ViewNode
}
const item = new TreeItem(label, state);
item.command = {
title: `Compare ${this.branch.name}${this.compareWithWorkingTree ? ' (working)' : ''} with${
GlyphChars.Ellipsis
}`,
command: 'gitlens.views.executeNodeCallback',
arguments: [() => this.compareWith()],
};
if (this._compareWith == null) {
item.command = {
title: `Compare ${this.branch.name}${this.compareWithWorkingTree ? ' (working)' : ''} with${
GlyphChars.Ellipsis
}`,
command: 'gitlens.views.editNode',
arguments: [this],
};
}
item.contextValue = `${ContextValues.CompareBranch}${this.branch.current ? '+current' : ''}+${
this.comparisonType
}${this._compareWith == null ? '' : '+comparing'}${this.root ? '+root' : ''}`;
@ -185,6 +187,11 @@ export class CompareBranchNode extends ViewNode
this.view.triggerNodeChange(this);
}
@log()
async edit() {
await this.compareWith();
}
@gate()
@debug()
refresh() {

+ 13
- 12
src/views/nodes/viewNode.ts Wyświetl plik

@ -157,10 +157,6 @@ export abstract class ViewRefFileNode extends ViewRef
}
}
export function nodeSupportsClearing(node: ViewNode): node is ViewNode & { clear(): void | Promise<void> } {
return typeof (node as ViewNode & { clear(): void | Promise<void> }).clear === 'function';
}
export interface PageableViewNode {
readonly id: string;
limit?: number;
@ -188,7 +184,7 @@ export abstract class SubscribeableViewNode extends V
this.view.onDidChangeNodeCollapsibleState(this.onNodeCollapsibleStateChanged, this),
];
if (viewSupportsAutoRefresh(this.view)) {
if (canAutoRefreshView(this.view)) {
disposables.push(this.view.onDidChangeAutoRefresh(this.onAutoRefreshChanged, this));
}
@ -290,11 +286,7 @@ export abstract class SubscribeableViewNode extends V
@debug()
async ensureSubscription() {
// We only need to subscribe if we are visible and if auto-refresh enabled (when supported)
if (
!this.canSubscribe ||
!this.view.visible ||
(viewSupportsAutoRefresh(this.view) && !this.view.autoRefresh)
) {
if (!this.canSubscribe || !this.view.visible || (canAutoRefreshView(this.view) && !this.view.autoRefresh)) {
await this.unsubscribe();
return;
@ -438,10 +430,19 @@ interface AutoRefreshableView {
autoRefresh: boolean;
onDidChangeAutoRefresh: Event<void>;
}
export function viewSupportsAutoRefresh(view: View): view is View & AutoRefreshableView {
export function canAutoRefreshView(view: View): view is View & AutoRefreshableView {
return Functions.is<View & AutoRefreshableView>(view, 'onDidChangeAutoRefresh');
}
export function viewSupportsNodeDismissal(view: View): view is View & { dismissNode(node: ViewNode): void } {
export function canClearNode(node: ViewNode): node is ViewNode & { clear(): void | Promise<void> } {
return typeof (node as ViewNode & { clear(): void | Promise<void> }).clear === 'function';
}
export function canEditNode(node: ViewNode): node is ViewNode & { edit(): void | Promise<void> } {
return typeof (node as ViewNode & { edit(): void | Promise<void> }).edit === 'function';
}
export function canViewDismissNode(view: View): view is View & { dismissNode(node: ViewNode): void } {
return typeof (view as View & { dismissNode(node: ViewNode): void }).dismissNode === 'function';
}

+ 0
- 7
src/views/searchAndCompareView.ts Wyświetl plik

@ -293,7 +293,6 @@ export class SearchAndCompareView extends ViewBase
commands.registerCommand(this.getQualifiedCommand('pin'), this.pin, this);
commands.registerCommand(this.getQualifiedCommand('unpin'), this.unpin, this);
commands.registerCommand(this.getQualifiedCommand('edit'), this.edit, this);
commands.registerCommand(this.getQualifiedCommand('swapComparison'), this.swapComparison, this);
commands.registerCommand(this.getQualifiedCommand('selectForCompare'), this.selectForCompare, this);
commands.registerCommand(this.getQualifiedCommand('compareWithSelected'), this.compareWithSelected, this);
@ -466,12 +465,6 @@ export class SearchAndCompareView extends ViewBase
setImmediate(() => this.reveal(results, options));
}
private edit(node: SearchResultsNode) {
if (!(node instanceof SearchResultsNode)) return undefined;
return node.edit();
}
private setFilesLayout(layout: ViewFilesLayout) {
return configuration.updateEffective('views', this.configKey, 'files', 'layout', layout);
}

+ 29
- 32
src/views/viewCommands.ts Wyświetl plik

@ -21,6 +21,9 @@ import {
BranchesNode,
BranchNode,
BranchTrackingStatusNode,
canClearNode,
canEditNode,
canViewDismissNode,
CommitFileNode,
CommitNode,
CompareBranchNode,
@ -31,7 +34,6 @@ import {
FolderNode,
LineHistoryNode,
MergeConflictFileNode,
nodeSupportsClearing,
PageableViewNode,
PagerNode,
PullRequestNode,
@ -49,7 +51,6 @@ import {
ViewNode,
ViewRefFileNode,
ViewRefNode,
viewSupportsNodeDismissal,
} from './nodes';
import { debug } from '../system';
import { runGitCommandInTerminal } from '../terminal';
@ -63,6 +64,7 @@ interface CompareSelectedInfo {
export class ViewCommands {
constructor() {
commands.registerCommand('gitlens.views.clearNode', (n: ViewNode) => canClearNode(n) && n.clear(), this);
commands.registerCommand(
'gitlens.views.copy',
async (selection: ViewNode | ViewNode[]) => {
@ -78,35 +80,30 @@ export class ViewCommands {
this,
);
commands.registerCommand(
'gitlens.views.refreshNode',
(node: ViewNode, reset?: boolean) => {
if (reset == null && PageableViewNode.is(node)) {
node.limit = undefined;
node.view.resetNodeLastKnownLimit(node);
}
return node.view.refreshNode(node, reset == null ? true : reset);
},
'gitlens.views.dismissNode',
(n: ViewNode) => canViewDismissNode(n.view) && n.view.dismissNode(n),
this,
);
commands.registerCommand('gitlens.views.editNode', (n: ViewNode) => canEditNode(n) && n.edit(), this);
commands.registerCommand(
'gitlens.views.expandNode',
(node: ViewNode) => node.view.reveal(node, { select: false, focus: false, expand: 3 }),
(n: ViewNode) => n.view.reveal(n, { select: false, focus: false, expand: 3 }),
this,
);
commands.registerCommand('gitlens.views.loadMoreChildren', (n: PagerNode) => n.loadMore(), this);
commands.registerCommand('gitlens.views.loadAllChildren', (n: PagerNode) => n.loadAll(), this);
commands.registerCommand(
'gitlens.views.clearNode',
(node: ViewNode) => nodeSupportsClearing(node) && node.clear(),
this,
);
commands.registerCommand(
'gitlens.views.dismissNode',
(node: ViewNode) => viewSupportsNodeDismissal(node.view) && node.view.dismissNode(node),
'gitlens.views.refreshNode',
(n: ViewNode, reset?: boolean) => {
if (reset == null && PageableViewNode.is(n)) {
n.limit = undefined;
n.view.resetNodeLastKnownLimit(n);
}
return n.view.refreshNode(n, reset == null ? true : reset);
},
this,
);
commands.registerCommand('gitlens.views.executeNodeCallback', (fn: <R>() => Promise<R>) => fn(), this);
commands.registerCommand('gitlens.views.loadMoreChildren', (node: PagerNode) => node.loadMore(), this);
commands.registerCommand('gitlens.views.loadAllChildren', (node: PagerNode) => node.loadAll(), this);
commands.registerCommand(
'gitlens.views.setShowRelativeDateMarkersOn',
@ -259,6 +256,16 @@ export class ViewCommands {
}
@debug()
private browseRepoAtRevision(node: ViewRefNode, options?: { before?: boolean; openInNewWindow?: boolean }) {
if (!(node instanceof ViewRefNode)) return Promise.resolve();
return GitActions.browseAtRevision(node.uri, {
before: options?.before,
openInNewWindow: options?.openInNewWindow,
});
}
@debug()
private cherryPick(node: CommitNode) {
if (!(node instanceof CommitNode)) return Promise.resolve();
@ -337,16 +344,6 @@ export class ViewCommands {
}
@debug()
private browseRepoAtRevision(node: ViewRefNode, options?: { before?: boolean; openInNewWindow?: boolean }) {
if (!(node instanceof ViewRefNode)) return Promise.resolve();
return GitActions.browseAtRevision(node.uri, {
before: options?.before,
openInNewWindow: options?.openInNewWindow,
});
}
@debug()
private fetch(node: RemoteNode | RepositoryNode | BranchNode | BranchTrackingStatusNode) {
if (node instanceof RepositoryNode) return GitActions.fetch(node.repo);
if (node instanceof RemoteNode) return GitActions.Remote.fetch(node.remote.repoPath, node.remote.name);

Ładowanie…
Anuluj
Zapisz