SCM - add history item hover (#209373)

This commit is contained in:
Ladislau Szomoru
2024-04-02 21:16:51 +02:00
committed by GitHub
parent ac37049b6b
commit ea29ccb86f
@@ -106,8 +106,9 @@ import { CancellationTokenSource } from 'vs/base/common/cancellation';
import { DropdownWithPrimaryActionViewItem } from 'vs/platform/actions/browser/dropdownWithPrimaryActionViewItem';
import { clamp } from 'vs/base/common/numbers';
import { ILogService } from 'vs/platform/log/common/log';
import { ICustomHover, setupCustomHover } from 'vs/base/browser/ui/hover/updatableHoverWidget';
import { ICustomHover, ITooltipMarkdownString, setupCustomHover } from 'vs/base/browser/ui/hover/updatableHoverWidget';
import { getDefaultHoverDelegate } from 'vs/base/browser/ui/hover/hoverDelegateFactory';
import { MarkdownString } from 'vs/base/common/htmlContent';
// type SCMResourceTreeNode = IResourceNode<ISCMResource, ISCMResourceGroup>;
// type SCMHistoryItemChangeResourceTreeNode = IResourceNode<SCMHistoryItemChangeTreeElement, SCMHistoryItemTreeElement>;
@@ -945,8 +946,9 @@ class HistoryItemRenderer implements ICompressibleTreeRenderer<SCMHistoryItemTre
templateData.iconContainer.classList.add(...ThemeIcon.asClassNameArray(historyItem.icon));
}
const title = this.getTooltip(historyItem);
const [matches, descriptionMatches] = this.processMatches(historyItem, node.filterData);
templateData.label.setLabel(historyItem.message, historyItem.author, { matches, descriptionMatches });
templateData.label.setLabel(historyItem.message, historyItem.author, { matches, descriptionMatches, title });
templateData.actionBar.clear();
templateData.actionBar.context = historyItem;
@@ -964,6 +966,23 @@ class HistoryItemRenderer implements ICompressibleTreeRenderer<SCMHistoryItemTre
throw new Error('Should never happen since node is incompressible');
}
private getTooltip(historyItem: SCMHistoryItemTreeElement): ITooltipMarkdownString {
const markdown = new MarkdownString('', { isTrusted: true, supportThemeIcons: true });
if (historyItem.author) {
markdown.appendMarkdown(`$(account) **${historyItem.author}**\n\n`);
}
if (historyItem.timestamp) {
const dateFormatter = new Intl.DateTimeFormat(platform.language, { year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric' });
markdown.appendMarkdown(`$(history) ${dateFormatter.format(historyItem.timestamp)}\n\n`);
}
markdown.appendMarkdown(historyItem.message);
return { markdown, markdownNotSupportedFallback: historyItem.message };
}
private processMatches(historyItem: SCMHistoryItemTreeElement, filterData: LabelFuzzyScore | undefined): [IMatch[] | undefined, IMatch[] | undefined] {
if (!filterData) {
return [undefined, undefined];