Skip to content

The IDE you know, rebuilt in Rust. IntelliJ IDEA–style keymap, tool windows and search-everywhere in a fast native app: editor, code insight, debugger, Git, terminal, database and HTTP clients for 60+ languages.

fix(vcs): stop hover flicker while scrolling the Git log (#2358)

Shohruh Ismoilov231c47b5cd11
diff --git a/e2e/gitLogScrollbar.spec.ts b/e2e/gitLogScrollbar.spec.ts
index 7ee19f28b..f2536143d 100644
--- a/e2e/gitLogScrollbar.spec.ts
+++ b/e2e/gitLogScrollbar.spec.ts
@@ -1,8 +1,6 @@
import { expect, stubDesktop, test } from "./fixtures";
-test("keeps a wide Git graph filled during scrollbar drags and its edges interactive afterwards", async ({
- workbench: page,
-}) => {
+test.beforeEach(async ({ workbench: page }) => {
await stubDesktop(page);
await page.evaluate(async () => {
const root = "/dev/acme-api";
@@ -72,7 +70,12 @@ test("keeps a wide Git graph filled during scrollbar drags and its edges interac
const { useGitLog, loadMore } = await import(/* @vite-ignore */ module);
while (!useGitLog.getState().done) await loadMore();
});
+});
+test("keeps a wide Git graph filled during scrollbar drags and its edges interactive afterwards", async ({
+ workbench: page,
+}) => {
+ const list = page.getByRole("listbox", { name: "Commits" });
const box = (await list.boundingBox())!;
const x = box.x + box.width - 5;
await page.mouse.move(x, box.y + 8);
@@ -104,3 +107,88 @@ test("keeps a wide Git graph filled during scrollbar drags and its edges interac
// Rows drawn mid-drag get their edge hit targets back once scrolling stops.
await expect(row.getByRole("button", { name: "Collapse this fragment" }).first()).toBeAttached();
});
+
+for (const delta of [26, 780]) {
+ test(`keeps hover feedback quiet under a stationary pointer while wheel-scrolling ${delta}px`, async ({
+ workbench: page,
+ }) => {
+ const list = page.getByRole("listbox", { name: "Commits" });
+ const row = list.getByRole("option").nth(3);
+ const node = row.locator('svg[aria-label="Commit graph"] > g');
+ await node.hover();
+ const hoverBackground = await row.evaluate((element) => getComputedStyle(element).backgroundColor);
+ const highlighted = list.locator('svg circle[r="6"], svg path[stroke-width="2.8"]');
+ await expect(highlighted.first()).toBeAttached();
+ const box = (await node.boundingBox())!;
+ const point = { x: box.x + box.width / 2, y: box.y + box.height / 2 };
+ const frames: { graph: number; row: boolean }[] = [];
+ for (let i = 0; i < 18; i++) {
+ await page.mouse.wheel(0, delta);
+ await page.waitForTimeout(25);
+ frames.push(
+ await list.evaluate(
+ (element, { point, hoverBackground }) => {
+ const hovered = document.elementFromPoint(point.x, point.y)?.closest('[role="option"]');
+ return {
+ graph: element.querySelectorAll('svg circle[r="6"], svg path[stroke-width="2.8"]').length,
+ row: !!hovered && getComputedStyle(hovered).backgroundColor === hoverBackground,
+ };
+ },
+ { point, hoverBackground },
+ ),
+ );
+ }
+ expect(await list.evaluate((element) => element.scrollTop)).toBeGreaterThan(200);
+ expect(
+ frames.filter((frame) => frame.graph > 0),
+ "graph highlights during scrolling",
+ ).toEqual([]);
+ expect(
+ frames.filter((frame) => frame.row),
+ "row hover backgrounds during scrolling",
+ ).toEqual([]);
+
+ await page.waitForTimeout(200);
+ await expect(highlighted).toHaveCount(0);
+ expect(
+ await page.evaluate(
+ ({ point, hoverBackground }) => {
+ const row = document.elementFromPoint(point.x, point.y)?.closest('[role="option"]');
+ return row && getComputedStyle(row).backgroundColor === hoverBackground;
+ },
+ { point, hoverBackground },
+ ),
+ "a stationary pointer does not reactivate hover after the scroll idle delay",
+ ).toBe(false);
+
+ // A click still selects a commit before the scroll idle delay has elapsed.
+ await page.mouse.wheel(0, delta);
+ await page.waitForTimeout(25);
+ const listBox = (await list.boundingBox())!;
+ await page.mouse.click(listBox.x + listBox.width - 100, point.y);
+ await expect(list.getByRole("option", { selected: true })).toHaveCount(1);
+
+ await page.waitForTimeout(200);
+ const visibleIndex = await list.evaluate((element) => Math.ceil(element.scrollTop / 26) + 2);
+ const visibleRow = list.locator(`[id="commit-log-${visibleIndex}"]`);
+ await visibleRow.locator('svg[aria-label="Commit graph"] > g').hover();
+ await expect(highlighted.first()).toBeAttached();
+ await expect(visibleRow).toHaveCSS("background-color", hoverBackground);
+ });
+}
+
+test("keeps recycled commit tooltips closed until the pointer moves after fast scrolling", async ({
+ workbench: page,
+}) => {
+ const list = page.getByRole("listbox", { name: "Commits" });
+ await list.getByText("Commit 3", { exact: true }).hover();
+ for (let i = 0; i < 18; i++) {
+ await page.mouse.wheel(0, 780);
+ await page.waitForTimeout(25);
+ }
+ await page.waitForTimeout(1000);
+ await expect(page.getByRole("tooltip")).toHaveCount(0);
+ const index = await list.evaluate((element) => Math.ceil(element.scrollTop / 26) + 2);
+ await list.getByText(`Commit ${index}`, { exact: true }).hover();
+ await expect(page.getByRole("tooltip")).toContainText(`Commit ${index}`);
+});
diff --git a/src/features/vcs/GitLog.module.css b/src/features/vcs/GitLog.module.css
index c43894ab9..d455d882a 100644
--- a/src/features/vcs/GitLog.module.css
+++ b/src/features/vcs/GitLog.module.css
@@ -239,6 +239,9 @@
.row:hover {
background: var(--bg-tree-hover);
}
+.list[data-hover-paused] .row:not(.columnHeader):hover {
+ background: var(--log-row-bg, transparent);
+}
.selected,
.selected:hover {
--log-row-bg: var(--bg-tree-selected-inactive);
diff --git a/src/features/vcs/GitLog.tsx b/src/features/vcs/GitLog.tsx
index e2598eb1f..93c8abf0e 100644
--- a/src/features/vcs/GitLog.tsx
+++ b/src/features/vcs/GitLog.tsx
@@ -1401,6 +1401,8 @@ function CommitList() {
const selectedSet = useMemo(() => new Set(selection), [selection]);
const revealTick = useGitLog((s) => s.revealTick);
const scrollRef = useRef<HTMLDivElement>(null);
+ // Recycled rows can emit enter events without the pointer moving.
+ const hoverPointer = useRef<{ x: number; y: number } | null>(null);
const previousRows = useRef(commits);
useLayoutEffect(() => {
const element = scrollRef.current;
@@ -1648,6 +1650,11 @@ function CommitList() {
rowEvents.current = {
onHover: (edge) => {
+ if (
+ edge === hoverColor ||
+ (edge && (virtualizer.isScrolling || scrollRef.current?.hasAttribute("data-hover-paused")))
+ )
+ return;
setHoverColor(edge);
if (!edge) return;
const source = displayedGraph.find((c) => c.parents.some((p) => `${c.id}\0${p}` === edge));
@@ -1704,6 +1711,19 @@ function CommitList() {
aria-multiselectable
aria-activedescendant={selectedIndex >= 0 ? `commit-${scope ?? "log"}-${selectedIndex}` : undefined}
tabIndex={0}
+ onScroll={(e) => {
+ if (!e.currentTarget.hasAttribute("data-hover-paused")) e.currentTarget.dataset.hoverPaused = "";
+ setHoverColor(null);
+ }}
+ onPointerMoveCapture={(e) => {
+ const previous = hoverPointer.current;
+ hoverPointer.current = { x: e.clientX, y: e.clientY };
+ if (!virtualizer.isScrolling && (!previous || previous.x !== e.clientX || previous.y !== e.clientY))
+ delete e.currentTarget.dataset.hoverPaused;
+ }}
+ onPointerLeave={(e) => {
+ hoverPointer.current = { x: e.clientX, y: e.clientY };
+ }}
onKeyDown={onKeyDown}
onCopy={(e) => {
if (window.getSelection()?.toString()) return;
@@ -2079,7 +2099,10 @@ function CommitRowView({
}, [tooltip]);
const enterTooltip = () => {
clearTimeout(tooltipTimer.current);
- tooltipTimer.current = setTimeout(() => setTooltip(true), TOOLTIP_DELAY);
+ 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);
@@ -2117,6 +2140,7 @@ function CommitRowView({
ref={subjectRef}
className={clsx(styles.subject, head && styles.headSubject, merge && styles.mergeSubject)}
onPointerEnter={enterTooltip}
+ onPointerMove={enterTooltip}
onPointerLeave={leaveTooltip}
onPointerDown={() => {
clearTimeout(tooltipTimer.current);
@@ -2281,6 +2305,7 @@ export function GraphCell({
tabIndex={actionable ? 0 : undefined}
aria-label={actionable ? label : undefined}
onMouseEnter={() => onHover?.(s.edge ?? `${s.source ?? ""}\0${target ?? ""}`)}
+ onMouseMove={() => onHover?.(s.edge ?? `${s.source ?? ""}\0${target ?? ""}`)}
onMouseDown={(e) => e.stopPropagation()}
onClick={(e) => {
e.stopPropagation();
@@ -2316,6 +2341,7 @@ export function GraphCell({
aria-label={onNode ? tx("Collapse or expand this branch") : undefined}
onMouseDown={(e) => e.stopPropagation()}
onMouseEnter={() => row.id && onHover?.(`node:${row.id}`)}
+ onMouseMove={() => row.id && onHover?.(`node:${row.id}`)}
onClick={(e) => {
e.stopPropagation();
onNode?.();