Файли
openidea/src/features/vcs/log/CommitRow.tsx
T
l0ng-ai 5b99b8b5ab fix(vcs): dim Git log metadata columns only for merge commits (#7119)
The User, Date and Hash cells in the Git log always used the muted color, while the subject is only dimmed for merge commits (Highlight > Merge Commits) and for commits outside the cherry-pick selection. The metadata cells now use the same condition, so a row is dimmed as a whole or not at all. My Commits still shows the author in bold.

Fixes #7112
2026-12-01 06:51:40 +08:00

248 рядки
8.3 KiB
TypeScript

import type { Commit } from "@/bindings";
import { Icon, Popup, TOOLTIP_DELAY, showContextMenu } from "@/ui";
import clsx from "clsx";
import { memo, useEffect, useRef, useState, type MouseEvent as ReactMouseEvent } from "react";
import styles from "../GitLog.module.css";
import { type GraphRow } from "../graph";
import { IssueText } from "../issueLinks";
import { type LogOptions } from "../logOptions";
import { selectedCommits } from "../logStore";
import { commitKey, commitRepo } from "../multiRoot";
import { repoName, useVcs } from "../store";
import { CommitMessage, RefLabels } from "./CommitMessage";
import { GraphCell } from "./GraphCell";
import { RowResizeHandle } from "./RowResizeHandle";
import { commitMenu } from "./commitMenu";
import { SUBJECT_COLUMN, columnSequence, type LogColumn } from "./shared";
import { REPOSITORY_WIDTH, columnPrev } from "./useColumnResize";
function CommitRowView({
id,
commit: c,
fileHistoryTarget,
graph,
top,
height,
selected,
head,
mine,
onBranch,
outsideUnpicked,
opts,
remoteNames,
onPick,
hoverColor,
highlighted,
highlightedNodes,
onHover,
onFragment,
onNavigate,
targetTitle,
columns,
bookmarked,
interactive,
}: {
id: string;
commit: Commit;
fileHistoryTarget: string | null;
graph: GraphRow | undefined;
top: number;
height: number;
selected: boolean;
head: boolean;
mine: boolean;
onBranch: boolean;
outsideUnpicked: boolean;
opts: LogOptions;
remoteNames: ReadonlySet<string>;
onPick: (id: string, e: ReactMouseEvent) => void;
hoverColor: string | null;
highlighted: ReadonlySet<string>;
highlightedNodes: ReadonlySet<string>;
onHover: (color: string | null) => void;
onFragment: (from: string, target: string, expand: boolean) => void;
onNavigate: (index: number, key?: string) => void;
targetTitle: (index: number, key?: string) => string;
columns: LogColumn[];
bookmarked: boolean;
/** False for rows rendered mid-scroll: their graph is drawn without hit targets. */
interactive: boolean;
}) {
const merge = opts.highlightMerges && c.parents.length > 1;
const subjectRef = useRef<HTMLSpanElement>(null);
const [tooltip, setTooltip] = useState(false);
const tooltipBody = useRef<HTMLDivElement>(null);
const tooltipTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
useEffect(() => () => clearTimeout(tooltipTimer.current), []);
useEffect(() => {
if (!tooltip) return;
// Scrolling the log moves the anchor away; scrolling a long message inside the card doesn't.
const hide = (e: Event) => {
const card = tooltipBody.current?.closest("[data-popup]");
if (e.target instanceof Node && card?.contains(e.target)) return;
setTooltip(false);
};
window.addEventListener("scroll", hide, true);
return () => window.removeEventListener("scroll", hide, true);
}, [tooltip]);
const enterTooltip = () => {
clearTimeout(tooltipTimer.current);
if (tooltip || subjectRef.current?.closest("[data-hover-paused]")) return;
tooltipTimer.current = setTimeout(() => {
if (!subjectRef.current?.closest("[data-hover-paused]")) setTooltip(true);
}, TOOLTIP_DELAY);
};
const leaveTooltip = () => {
clearTimeout(tooltipTimer.current);
tooltipTimer.current = setTimeout(() => setTooltip(false), 120);
};
const refs = c.refs.length > 0 && (
<RefLabels
refs={c.refs}
compact={opts.compactRefs}
tagNames={opts.tagNames}
remoteNames={remoteNames}
left={opts.refsOnLeft}
/>
);
const repository = opts.showRepository && !!commitRepo(c) && useVcs.getState().roots.length > 1;
// The header's neighbours: an id without a shown column (a hidden one) is skipped.
const visibleIds = columnSequence(opts.columnOrder, columns).filter(
(cid) => cid === SUBJECT_COLUMN.id || columns.some((col) => col.id === cid),
);
const subjectCell = (
<span key={SUBJECT_COLUMN.id} className={styles.colSubject}>
{/* A leading Commit cell's left edge is the only row divider for the Repository column. */}
{repository && visibleIds[0] === SUBJECT_COLUMN.id && (
<RowResizeHandle
target={{
id: SUBJECT_COLUMN.id,
width: 0,
...columnPrev(visibleIds, SUBJECT_COLUMN.id, opts, columns, repository),
leftOnly: true,
}}
/>
)}
{graph && (
<GraphCell
row={graph}
head={head}
activeColor={hoverColor}
highlighted={highlighted}
highlightedNodes={highlightedNodes}
onHover={onHover}
onNavigate={onNavigate}
targetTitle={targetTitle}
onFragment={(target, expand, source) => onFragment(source ?? commitKey(c), target, expand)}
onNode={() => onFragment(commitKey(c), commitKey(c), false)}
interactive={interactive}
/>
)}
{bookmarked && <Icon name="bookmark" size={12} />}
<span className={styles.commitText}>
{opts.refsOnLeft && refs}
<span
ref={subjectRef}
className={clsx(
styles.subject,
head && styles.headSubject,
(merge || outsideUnpicked) && styles.mergeSubject,
)}
onPointerEnter={enterTooltip}
onPointerMove={enterTooltip}
onPointerLeave={leaveTooltip}
onPointerDown={() => {
clearTimeout(tooltipTimer.current);
setTooltip(false);
}}
>
<span className={styles.subjectText}>
<IssueText text={c.summary} />
</span>
</span>
{!opts.refsOnLeft && refs}
</span>
<Popup
open={tooltip}
anchor={subjectRef}
role="tooltip"
autoFocus={false}
restoreFocus={false}
onClose={() => setTooltip(false)}
className={styles.commitTooltip}
>
<div ref={tooltipBody} onPointerEnter={() => clearTimeout(tooltipTimer.current)} onPointerLeave={leaveTooltip}>
<CommitMessage commit={c} />
</div>
</Popup>
</span>
);
return (
<div
id={id}
role="option"
aria-selected={selected}
className={clsx(
styles.row,
onBranch && styles.currentBranch,
selected && styles.selected,
opts.showColumnDividers && styles.showDividers,
)}
style={{ top, height }}
onMouseDown={(e) => {
if (e.shiftKey) e.preventDefault(); // no text selection on range clicks
onPick(commitKey(c), e);
}}
onContextMenu={(e) => {
e.preventDefault();
showContextMenu(e, commitMenu(c, selectedCommits(), fileHistoryTarget));
}}
>
{repository && (
<span
className={styles.colRepository}
style={{ width: opts.columnWidths.repository ?? REPOSITORY_WIDTH }}
title={commitRepo(c)!}
>
{repoName(commitRepo(c)!)}
</span>
)}
{visibleIds.map((cid, _index, ids) => {
if (cid === SUBJECT_COLUMN.id) return subjectCell;
const column = columns.find((col) => col.id === cid);
if (!column) return null;
const width = opts.columnWidths[column.id] ?? column.width ?? 120;
return (
<span
key={cid}
className={clsx(
styles.columnCell,
// Dimmed with the subject: merge commits and commits outside the cherry-pick selection.
(merge || outsideUnpicked) && styles.muted,
column.id === "author" && mine && styles.mine,
column.id === "hash" && styles.hash,
)}
style={{ width }}
title={column.id === "author" ? `${c.author} <${c.email}>` : undefined}
>
{column.render(c)}
<RowResizeHandle
target={{ id: column.id, width, ...columnPrev(ids, column.id, opts, columns, repository) }}
/>
</span>
);
})}
</div>
);
}
// A row that is already interactive stays so when scrolling starts; only rows
// whose content changes mid-scroll are drawn without hit targets.
export const CommitRow = memo(CommitRowView, (prev, next) => {
for (const key in next) {
const k = key as keyof typeof next;
if (prev[k] !== next[k] && !(k === "interactive" && prev.interactive)) return false;
}
return true;
});