Browse Source

Fixes branch/status tooltips

main
Eric Amodio 4 years ago
parent
commit
bef246c7c1
3 changed files with 15 additions and 10 deletions
  1. +4
    -1
      src/git/models/status.ts
  2. +4
    -3
      src/views/nodes/branchNode.ts
  3. +7
    -6
      src/views/nodes/branchTrackingStatusNode.ts

+ 4
- 1
src/git/models/status.ts View File

@ -199,9 +199,9 @@ export class GitStatus {
state: { ahead: number; behind: number }, state: { ahead: number; behind: number },
options: { empty?: string; expand?: boolean; prefix?: string; separator?: string; suffix?: string } = {}, options: { empty?: string; expand?: boolean; prefix?: string; separator?: string; suffix?: string } = {},
): string { ): string {
const { expand = false, prefix = '', separator = ' ', suffix = '' } = options;
if (upstream == null || (state.behind === 0 && state.ahead === 0)) return options.empty ?? ''; if (upstream == null || (state.behind === 0 && state.ahead === 0)) return options.empty ?? '';
const { expand, prefix = '', separator = ' ', suffix = '' } = options;
if (expand) { if (expand) {
let status = ''; let status = '';
if (state.behind) { if (state.behind) {
@ -209,6 +209,9 @@ export class GitStatus {
} }
if (state.ahead) { if (state.ahead) {
status += `${status.length === 0 ? '' : separator}${Strings.pluralize('commit', state.ahead)} ahead`; status += `${status.length === 0 ? '' : separator}${Strings.pluralize('commit', state.ahead)} ahead`;
if (suffix.endsWith(upstream)) {
status += ' of';
}
} }
return `${prefix}${status}${suffix}`; return `${prefix}${status}${suffix}`;
} }

+ 4
- 3
src/views/nodes/branchNode.ts View File

@ -213,10 +213,11 @@ export class BranchNode
GlyphChars.Space GlyphChars.Space
} ${this.branch.tracking}`; } ${this.branch.tracking}`;
tooltip += ` is tracking ${this.branch.tracking}\n${this.branch.getTrackingStatus({
empty: 'up-to-date',
tooltip += ` is ${this.branch.getTrackingStatus({
empty: `up to date with ${this.branch.tracking}`,
expand: true, expand: true,
separator: '\n',
separator: ', ',
suffix: ` ${this.branch.tracking}`,
})}`; })}`;
if (this.branch.state.ahead || this.branch.state.behind) { if (this.branch.state.ahead || this.branch.state.behind) {

+ 7
- 6
src/views/nodes/branchTrackingStatusNode.ts View File

@ -129,10 +129,10 @@ export class BranchTrackingStatusNode extends ViewNode implement
switch (this.upstreamType) { switch (this.upstreamType) {
case 'ahead': case 'ahead':
label = `${Strings.pluralize('commit', this.status.state.ahead)} ahead`; label = `${Strings.pluralize('commit', this.status.state.ahead)} ahead`;
tooltip = `${this.branch.name} is ${label} of ${this.status.upstream}`;
if (!this.isReposView) { if (!this.isReposView) {
label = `${this.root ? `${this.branch.name} is ` : ''}${label} of ${this.status.upstream}`; label = `${this.root ? `${this.branch.name} is ` : ''}${label} of ${this.status.upstream}`;
} }
tooltip = `${label} of ${this.status.upstream}`;
collapsibleState = !this.isReposView collapsibleState = !this.isReposView
? TreeItemCollapsibleState.Expanded ? TreeItemCollapsibleState.Expanded
@ -146,10 +146,10 @@ export class BranchTrackingStatusNode extends ViewNode implement
case 'behind': case 'behind':
label = `${Strings.pluralize('commit', this.status.state.behind)} behind`; label = `${Strings.pluralize('commit', this.status.state.behind)} behind`;
tooltip = `${this.branch.name} is ${label} ${this.status.upstream}`;
if (!this.isReposView) { if (!this.isReposView) {
label = `${this.root ? `${this.branch.name} is ` : ''}${label} ${this.status.upstream}`; label = `${this.root ? `${this.branch.name} is ` : ''}${label} ${this.status.upstream}`;
} }
tooltip = `${label} ${this.status.upstream}`;
collapsibleState = TreeItemCollapsibleState.Collapsed; collapsibleState = TreeItemCollapsibleState.Collapsed;
contextValue = this.root contextValue = this.root
@ -161,10 +161,10 @@ export class BranchTrackingStatusNode extends ViewNode implement
case 'same': case 'same':
label = `${this.branch.name} is up to date`; label = `${this.branch.name} is up to date`;
tooltip = `${label} with ${this.status.upstream}`;
if (!this.isReposView) { if (!this.isReposView) {
label += ` with ${this.status.upstream}`; label += ` with ${this.status.upstream}`;
} }
tooltip = `${label} with ${this.status.upstream}`;
collapsibleState = TreeItemCollapsibleState.None; collapsibleState = TreeItemCollapsibleState.None;
contextValue = this.root ? ContextValues.StatusSameAsUpstream : undefined; contextValue = this.root ? ContextValues.StatusSameAsUpstream : undefined;
@ -185,9 +185,10 @@ export class BranchTrackingStatusNode extends ViewNode implement
const item = new TreeItem(label, collapsibleState); const item = new TreeItem(label, collapsibleState);
item.id = this.id; item.id = this.id;
item.contextValue = contextValue; item.contextValue = contextValue;
item.description = lastFetched
? `Last fetched ${Dates.getFormatter(new Date(lastFetched)).fromNow()}`
: undefined;
if (lastFetched) {
item.description = `Last fetched ${Dates.getFormatter(new Date(lastFetched)).fromNow()}`;
tooltip += `\n${item.description}`;
}
item.iconPath = new ThemeIcon(icon); item.iconPath = new ThemeIcon(icon);
item.tooltip = tooltip; item.tooltip = tooltip;

Loading…
Cancel
Save