Git - improve timeline hover (#237365)
parent
069a3c1ba1
commit
e22e3e7293
|
@ -265,9 +265,9 @@ export class GitBlameController {
|
|||
markdownString.appendMarkdown(`\n\n---\n\n`);
|
||||
}
|
||||
|
||||
markdownString.appendMarkdown(`[\`$(git-commit) ${getCommitShortHash(documentUri, blameInformationOrCommit.hash)} \`](command:git.blameStatusBarItem.viewCommit?${encodeURIComponent(JSON.stringify([documentUri, blameInformationOrCommit.hash]))} "${l10n.t('View Commit')}")`);
|
||||
markdownString.appendMarkdown(`[\`$(git-commit) ${getCommitShortHash(documentUri, blameInformationOrCommit.hash)} \`](command:git.viewCommit2?${encodeURIComponent(JSON.stringify([documentUri, blameInformationOrCommit.hash]))} "${l10n.t('View Commit')}")`);
|
||||
markdownString.appendMarkdown(' ');
|
||||
markdownString.appendMarkdown(`[$(copy)](command:git.blameStatusBarItem.copyContent?${encodeURIComponent(JSON.stringify(blameInformationOrCommit.hash))} "${l10n.t('Copy Commit Hash')}")`);
|
||||
markdownString.appendMarkdown(`[$(copy)](command:git.copyContentToClipboard?${encodeURIComponent(JSON.stringify(blameInformationOrCommit.hash))} "${l10n.t('Copy Commit Hash')}")`);
|
||||
markdownString.appendMarkdown(' | ');
|
||||
markdownString.appendMarkdown(`[$(gear)](command:workbench.action.openSettings?%5B%22git.blame%22%5D "${l10n.t('Open Settings')}")`);
|
||||
|
||||
|
@ -702,7 +702,7 @@ class GitBlameStatusBarItem {
|
|||
this._statusBarItem.tooltip = this._controller.getBlameInformationHover(window.activeTextEditor.document.uri, blameInformation[0].blameInformation);
|
||||
this._statusBarItem.command = {
|
||||
title: l10n.t('View Commit'),
|
||||
command: 'git.blameStatusBarItem.viewCommit',
|
||||
command: 'git.viewCommit2',
|
||||
arguments: [window.activeTextEditor.document.uri, blameInformation[0].blameInformation.hash]
|
||||
} satisfies Command;
|
||||
}
|
||||
|
|
|
@ -4346,8 +4346,8 @@ export class CommandCenter {
|
|||
env.clipboard.writeText(historyItem.message);
|
||||
}
|
||||
|
||||
@command('git.blameStatusBarItem.viewCommit', { repository: true })
|
||||
async viewStatusBarCommit(repository: Repository, historyItemId: string): Promise<void> {
|
||||
@command('git.viewCommit2', { repository: true })
|
||||
async viewCommit2(repository: Repository, historyItemId: string): Promise<void> {
|
||||
if (!repository || !historyItemId) {
|
||||
return;
|
||||
}
|
||||
|
@ -4365,8 +4365,8 @@ export class CommandCenter {
|
|||
await commands.executeCommand('_workbench.openMultiDiffEditor', { multiDiffSourceUri, title, resources });
|
||||
}
|
||||
|
||||
@command('git.blameStatusBarItem.copyContent')
|
||||
async blameStatusBarCopyContent(content: string): Promise<void> {
|
||||
@command('git.copyContentToClipboard')
|
||||
async copyContentToClipboard(content: string): Promise<void> {
|
||||
if (typeof content !== 'string') {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ export interface LogFileOptions {
|
|||
/** Optional. Specifies whether to start retrieving log entries in reverse order. */
|
||||
readonly reverse?: boolean;
|
||||
readonly sortByAuthorDate?: boolean;
|
||||
readonly shortStats?: boolean;
|
||||
}
|
||||
|
||||
function parseVersion(raw: string): string {
|
||||
|
@ -1290,6 +1291,10 @@ export class Repository {
|
|||
}
|
||||
}
|
||||
|
||||
if (options?.shortStats) {
|
||||
args.push('--shortstat');
|
||||
}
|
||||
|
||||
if (options?.sortByAuthorDate) {
|
||||
args.push('--author-date-order');
|
||||
}
|
||||
|
|
|
@ -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(`, <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(' ');
|
||||
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) {
|
||||
|
|
|
@ -1162,7 +1162,7 @@ class TimelineTreeRenderer implements ITreeRenderer<TreeElement, FuzzyScore, Tim
|
|||
@IThemeService private themeService: IThemeService,
|
||||
) {
|
||||
this.actionViewItemProvider = createActionViewItem.bind(undefined, this.instantiationService);
|
||||
this._hoverDelegate = this.instantiationService.createInstance(WorkbenchHoverDelegate, 'element', false, {
|
||||
this._hoverDelegate = this.instantiationService.createInstance(WorkbenchHoverDelegate, 'element', true, {
|
||||
position: {
|
||||
hoverPosition: HoverPosition.RIGHT // Will flip when there's no space
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue