fix(vcs): keep the Git log commit card open while scrolling inside it (#3691)

A commit row closed its card on any capture-phase scroll so that scrolling the log, which moves the anchor, hides it; scrolling a long message inside the card fired the same listener. Scrolls inside the card no longer close it; the log and elsewhere still do.

Co-authored-by: wildcatDownstairs <26499420+wildcatDownstairs@users.noreply.github.com>
This commit is contained in:
LU XIANGRUI
2026-11-16 14:25:44 +08:00
committed by GitHub
co-authored by wildcatDownstairs
parent 9adf35b097
commit de107e145c
2 changed files with 30 additions and 3 deletions
+22 -1
View File
@@ -40,7 +40,11 @@ test.beforeEach(async ({ workbench: page }) => {
h.vcs_commit_files = () => [];
h.vcs_log_details_batch = ({ revisions }) =>
(revisions as string[]).map((revision) => ({
message: `Commit ${parseInt(revision, 16)}`,
// Commit 2 carries a message longer than its tooltip.
message:
parseInt(revision, 16) === 2
? `Commit 2\n\n${Array.from({ length: 80 }, (_, i) => `Line ${i + 1}`).join("\n")}`
: `Commit ${parseInt(revision, 16)}`,
containingBranches: [],
signature: "N",
signer: "",
@@ -192,3 +196,20 @@ test("keeps recycled commit tooltips closed until the pointer moves after fast s
await list.getByText(`Commit ${index}`, { exact: true }).hover();
await expect(page.getByRole("tooltip")).toContainText(`Commit ${index}`);
});
test("keeps a commit tooltip open while its long message scrolls, and closes it when the log scrolls", async ({
workbench: page,
}) => {
const list = page.getByRole("listbox", { name: "Commits" });
await list.getByText("Commit 2", { exact: true }).hover();
const tooltip = page.getByRole("tooltip");
await expect(tooltip).toContainText("Line 80");
const box = (await tooltip.boundingBox())!;
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2, { steps: 5 });
await page.mouse.wheel(0, 400);
await expect.poll(() => tooltip.evaluate((element) => element.scrollTop)).toBeGreaterThan(0);
await page.waitForTimeout(300);
await expect(tooltip).toBeVisible();
await list.evaluate((element) => (element.scrollTop += 260));
await expect(tooltip).toHaveCount(0);
});
+8 -2
View File
@@ -2122,11 +2122,17 @@ function CommitRowView({
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;
const hide = () => setTooltip(false);
// 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]);
@@ -2192,7 +2198,7 @@ function CommitRowView({
onClose={() => setTooltip(false)}
className={styles.commitTooltip}
>
<div onPointerEnter={() => clearTimeout(tooltipTimer.current)} onPointerLeave={leaveTooltip}>
<div ref={tooltipBody} onPointerEnter={() => clearTimeout(tooltipTimer.current)} onPointerLeave={leaveTooltip}>
<CommitMessage commit={c} />
</div>
</Popup>