Git - improve timeline hover (#237365)

This commit is contained in:
Ladislau Szomoru
2025-01-06 21:47:43 +01:00
committed by GitHub
parent 069a3c1ba1
commit e22e3e7293
5 changed files with 52 additions and 16 deletions

View File

@@ -10,6 +10,8 @@ import { debounce } from './decorators';
import { emojify, ensureEmojis } from './emoji';
import { CommandCenter } from './commands';
import { OperationKind, OperationResult } from './operation';
import { getCommitShortHash } from './util';
import { CommitShortStat } from './git';
export class GitTimelineItem extends TimelineItem {
static is(item: TimelineItem): item is GitTimelineItem {
@@ -48,18 +50,46 @@ export class GitTimelineItem extends TimelineItem {
return this.shortenRef(this.previousRef);
}
setItemDetails(author: string, email: string | undefined, date: string, message: string): void {
setItemDetails(uri: Uri, hash: string | undefined, author: string, email: string | undefined, date: string, message: string, shortStat?: CommitShortStat): void {
this.tooltip = new MarkdownString('', true);
this.tooltip.isTrusted = true;
this.tooltip.supportHtml = true;
if (email) {
const emailTitle = l10n.t('Email');
this.tooltip.appendMarkdown(`$(account) [**${author}**](mailto:${email} "${emailTitle} ${author}")\n\n`);
this.tooltip.appendMarkdown(`$(account) [**${author}**](mailto:${email} "${emailTitle} ${author}")`);
} else {
this.tooltip.appendMarkdown(`$(account) **${author}**\n\n`);
this.tooltip.appendMarkdown(`$(account) **${author}**`);
}
this.tooltip.appendMarkdown(`$(history) ${date}\n\n`);
this.tooltip.appendMarkdown(message);
this.tooltip.appendMarkdown(`, $(history) ${date}\n\n`);
this.tooltip.appendMarkdown(`${message}\n\n`);
if (shortStat) {
this.tooltip.appendMarkdown(`---\n\n`);
if (shortStat.insertions) {
this.tooltip.appendMarkdown(`<span style="color:var(--vscode-scmGraph-historyItemHoverAdditionsForeground);">${shortStat.insertions === 1 ?
l10n.t('{0} insertion{1}', shortStat.insertions, '(+)') :
l10n.t('{0} insertions{1}', shortStat.insertions, '(+)')}</span>`);
}
if (shortStat.deletions) {
this.tooltip.appendMarkdown(`,&nbsp;<span style="color:var(--vscode-scmGraph-historyItemHoverDeletionsForeground);">${shortStat.deletions === 1 ?
l10n.t('{0} deletion{1}', shortStat.deletions, '(-)') :
l10n.t('{0} deletions{1}', shortStat.deletions, '(-)')}</span>`);
}
this.tooltip.appendMarkdown(`\n\n`);
}
if (hash) {
this.tooltip.appendMarkdown(`---\n\n`);
this.tooltip.appendMarkdown(`[\`$(git-commit) ${getCommitShortHash(uri, hash)} \`](command:git.viewCommit2?${encodeURIComponent(JSON.stringify([uri, hash]))} "${l10n.t('View Commit')}")`);
this.tooltip.appendMarkdown('&nbsp;');
this.tooltip.appendMarkdown(`[$(copy)](command:git.copyContentToClipboard?${encodeURIComponent(JSON.stringify(hash))} "${l10n.t('Copy Commit Hash')}")`);
}
}
private shortenRef(ref: string): string {
@@ -153,6 +183,7 @@ export class GitTimelineProvider implements TimelineProvider {
maxEntries: limit,
hash: options.cursor,
follow: true,
shortStats: true,
// sortByAuthorDate: true
});
@@ -184,7 +215,7 @@ export class GitTimelineProvider implements TimelineProvider {
item.description = c.authorName;
}
item.setItemDetails(c.authorName!, c.authorEmail, dateFormatter.format(date), message);
item.setItemDetails(uri, c.hash, c.authorName!, c.authorEmail, dateFormatter.format(date), message, c.shortStat);
const cmd = this.commands.resolveTimelineOpenDiffCommand(item, uri);
if (cmd) {
@@ -209,7 +240,7 @@ export class GitTimelineProvider implements TimelineProvider {
// TODO@eamodio: Replace with a better icon -- reflecting its status maybe?
item.iconPath = new ThemeIcon('git-commit');
item.description = '';
item.setItemDetails(you, undefined, dateFormatter.format(date), Resource.getStatusText(index.type));
item.setItemDetails(uri, undefined, you, undefined, dateFormatter.format(date), Resource.getStatusText(index.type));
const cmd = this.commands.resolveTimelineOpenDiffCommand(item, uri);
if (cmd) {
@@ -231,7 +262,7 @@ export class GitTimelineProvider implements TimelineProvider {
const item = new GitTimelineItem('', index ? '~' : 'HEAD', l10n.t('Uncommitted Changes'), date.getTime(), 'working', 'git:file:working');
item.iconPath = new ThemeIcon('circle-outline');
item.description = '';
item.setItemDetails(you, undefined, dateFormatter.format(date), Resource.getStatusText(working.type));
item.setItemDetails(uri, undefined, you, undefined, dateFormatter.format(date), Resource.getStatusText(working.type));
const cmd = this.commands.resolveTimelineOpenDiffCommand(item, uri);
if (cmd) {