From 084be4fb5139636db1bc3ccfd8ddf350cab909cf Mon Sep 17 00:00:00 2001 From: Muu Date: Tue, 17 Nov 2026 19:43:43 +0800 Subject: [PATCH] fix(vcs): Git Log column dividers, resize direction and Hide Column (#3879) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Dragging a Git Log column divider moved the wrong way and could shift unrelated columns, and the resize target was hard to find. The divider now sits on a column's left edge, follows the pointer, and resizes only its two neighbours; the flexible Commit column gets a header divider that resizes the column to its left. Visible dividers are an opt-in View Options › Columns › Column Dividers (off by default; the hit strip and resize cursor always work), and the column header menu can hide any column except Commit. Co-authored-by: muutot <92625353+muutot@users.noreply.github.com> --- src/features/vcs/GitLog.module.css | 72 ++++++++- .../vcs/__tests__/logUiFeatures.test.tsx | 132 +++++++++++++++- src/features/vcs/log/ColumnHeaders.tsx | 125 +++++++-------- src/features/vcs/log/ColumnResizeHandle.tsx | 49 ++++++ src/features/vcs/log/CommitRow.tsx | 15 +- src/features/vcs/log/FilterBar.tsx | 1 + src/features/vcs/log/RowResizeHandle.tsx | 9 ++ src/features/vcs/log/useColumnResize.ts | 144 ++++++++++++++++++ src/features/vcs/logOptions.ts | 3 + src/platform/locales/text/en.json | 3 + src/platform/locales/text/zh.json | 5 +- 11 files changed, 478 insertions(+), 80 deletions(-) create mode 100644 src/features/vcs/log/ColumnResizeHandle.tsx create mode 100644 src/features/vcs/log/RowResizeHandle.tsx create mode 100644 src/features/vcs/log/useColumnResize.ts diff --git a/src/features/vcs/GitLog.module.css b/src/features/vcs/GitLog.module.css index 389f09820..7bd251bd5 100644 --- a/src/features/vcs/GitLog.module.css +++ b/src/features/vcs/GitLog.module.css @@ -202,6 +202,11 @@ flex: none; overflow: hidden; text-overflow: ellipsis; + /* Keep the first glyph clear of the divider on this column's left edge. + box-sizing: border-box keeps the width and boundary position unchanged. */ + padding-inline-start: var(--space-2); + /* Anchor for the full-height column resize strip (IDEA's invisible divider). */ + position: relative; } .columnHeading { position: relative; @@ -219,17 +224,75 @@ .columnHeading.dropAfter { box-shadow: inset -2px 0 0 var(--accent); } +/* Column divider: an 8px hit strip centred on the column's LEFT edge, with a + visible rule and grip so the resize target is easy to see and grab. Each row + carries one, so the rule runs the full table height. */ .columnResize { position: absolute; inset-block: 0; - inset-inline-end: 0; - width: 6px; + /* Keep the strip centre (and rule) at the cell's left edge: the cell has + overflow:hidden, so any rule drawn into the 8px gap would be clipped away. */ + inset-inline-start: -4px; + width: 8px; cursor: ew-resize; touch-action: none; + z-index: 1; + display: flex; + align-items: center; + justify-content: center; +} +/* Divider line is opt-in (View Options › Columns › Column Dividers, off by + default like IDEA). The transparent hit strip and resize cursor always work; + only the paint is gated. */ +.columnResize::before, +.columnResize::after { + content: ""; + display: none; +} +.showDividers .columnResize::before { + display: block; + position: absolute; + inset-block: 0; + inset-inline-start: 4px; + width: 1px; + background: var(--border-strong); +} +.showDividers .columnResize::after { + display: block; + width: 2px; + height: 16px; + border-radius: 1px; + background: var(--control-off); +} +.showDividers .columnResize:hover::before, +.showDividers .columnResize:active::before { + background: var(--accent); + width: 2px; +} +.showDividers .columnResize:hover::after, +.showDividers .columnResize:active::after { + background: var(--accent); +} +/* First column's border: visible only when dividers are on, never draggable. */ +.columnResizeDisabled { + cursor: default; +} +.showDividers .columnResizeDisabled::after { + display: none; +} +.showDividers .columnResizeDisabled:hover::before, +.showDividers .columnResizeDisabled:active::before { + background: var(--border-strong); + width: 1px; +} +/* Data-row strips keep the full-height rule but not the repeating grip. */ +.columnResizeRow::after { + display: none; } .columnResize:focus-visible { outline: 2px solid var(--focus-ring); - outline-offset: -2px; + outline-offset: -1px; + border-radius: 1px; } /* View Options › Highlight › Current Branch: commits reachable from HEAD are tinted. */ .currentBranch { @@ -256,6 +319,9 @@ display: flex; align-items: center; gap: var(--space-1-5); + /* Anchor for the left divider. The graph SVG uses lane-relative coordinates, + so a positioned parent does not move it. */ + position: relative; /* Let graph endpoints overlap adjacent rows, but never paint over the next column. */ overflow-x: clip; overflow-y: visible; diff --git a/src/features/vcs/__tests__/logUiFeatures.test.tsx b/src/features/vcs/__tests__/logUiFeatures.test.tsx index 609245f38..88822c79e 100644 --- a/src/features/vcs/__tests__/logUiFeatures.test.tsx +++ b/src/features/vcs/__tests__/logUiFeatures.test.tsx @@ -157,7 +157,7 @@ describe("log controls", () => { useLogOptions.setState({ showColumnHeaders: true }); render(); const author = await screen.findByRole("separator", { name: "Resize Author column" }); - fireEvent.keyDown(author, { key: "ArrowRight" }); + fireEvent.keyDown(author, { key: "ArrowLeft" }); expect(useLogOptions.getState().columnWidths.author).toBe(140); fireEvent.keyDown(author, { key: "ArrowRight", altKey: true }); expect(useLogOptions.getState().columnOrder).toEqual(["subject", "date", "author", "hash"]); @@ -179,6 +179,132 @@ describe("log controls", () => { }, ); + it("Commit's left divider is header-only, resizes its left neighbour, and is inert when first", async () => { + // Commit leads by default: its left divider exists but cannot be dragged. + useLogOptions.setState({ showColumnHeaders: true, columnOrder: ["author", "date"] }); + render(); + const commitBorder = await screen.findByRole("separator", { name: "Commit column border" }); + expect(commitBorder.tabIndex).toBe(-1); + expect(useLogOptions.getState().columnWidths.author).toBeUndefined(); + + // Data rows have no Commit divider. + expect(document.querySelector('[role="option"] [class*="colSubject"] [class*="columnResize"]')).toBeNull(); + }); + + it("dragging Commit's divider grows the column to its left and shrinks Commit", async () => { + // Put Hash before Commit so the divider has a left neighbour to resize. + // subject must be listed explicitly after hash, else columnSequence puts it first. + useLogOptions.setState({ + showColumnHeaders: true, + showHash: true, + columnOrder: ["hash", "subject", "author", "date"], + }); + render(); + const handle = await screen.findByRole("separator", { name: "Resize Commit column" }); + handle.setPointerCapture = vi.fn(); + handle.hasPointerCapture = () => true; + handle.releasePointerCapture = vi.fn(); + // Drag left: the divider follows the pointer, so the left neighbour (Hash) + // shrinks and Commit (flex) grows. Default Hash width is 72 -> 42. + fireEvent.pointerDown(handle, { button: 0, pointerId: 7, clientX: 100 }); + fireEvent.pointerMove(handle, { pointerId: 7, clientX: 70 }); + fireEvent.pointerUp(handle, { pointerId: 7, clientX: 70 }); + expect(useLogOptions.getState().columnWidths.hash).toBe(42); // 72 - 30 + }); + + it("hides column dividers by default and shows them via the option", async () => { + useLogOptions.setState({ showColumnHeaders: true, showColumnDividers: false }); + const { rerender } = render(); + await screen.findByRole("separator", { name: "Resize Author column" }); + const sep = screen.getByRole("separator", { name: "Resize Author column" }); + // Hit strip and cursor stay active, but no rule is painted by default. + expect(sep.className).toMatch(/columnResize/); + expect(sep.closest('[class*="showDividers"]')).toBeNull(); + act(() => useLogOptions.setState({ showColumnDividers: true })); + rerender(); + expect( + screen.getByRole("separator", { name: "Resize Author column" }).closest('[class*="showDividers"]'), + ).not.toBeNull(); + }); + + it("hides a column from the header context menu", async () => { + useLogOptions.setState({ showColumnHeaders: true }); + render( + <> + + + , + ); + const author = document.querySelector('[data-log-column="author"]')!; + fireEvent.contextMenu(author, { bubbles: true, clientX: 10, clientY: 10 }); + fireEvent.click(await screen.findByRole("menuitem", { name: "Hide Column" })); + expect(useLogOptions.getState().showAuthor).toBe(false); + }); + + it("exposes a full-height column divider on data rows", async () => { + useLogOptions.setState({ showColumnHeaders: true }); + render(); + await screen.findByRole("separator", { name: "Resize Author column" }); + const header = screen.getByRole("separator", { name: "Resize Author column" }); + expect(header.className).toMatch(/columnResize/); + // Data rows carry the same strips so the divider — and its visible rule — + // spans the whole table height, not just the header. + const rowStrips = [...document.querySelectorAll('[role="option"] [class*="columnResize"]')]; + expect(rowStrips.length).toBeGreaterThan(0); + for (const strip of rowStrips) { + expect(strip.getAttribute("aria-hidden")).toBe("true"); + expect(strip.className).toMatch(/columnResize/); + } + }); + + it("resizes from a data-row strip and auto-fits on double-click", async () => { + useLogOptions.setState({ showColumnHeaders: true }); + render(); + await screen.findByRole("separator", { name: "Resize Author column" }); + const rows = within(screen.getByRole("listbox", { name: "Commits" })).getAllByRole("option"); + const rowStrip = rows[0]!.querySelector('[class*="columnResize"]')!; + const release = vi.fn(); + rowStrip.setPointerCapture = vi.fn(); + rowStrip.hasPointerCapture = () => true; + rowStrip.releasePointerCapture = release; + // The strip is on the column's left edge: drag left -> wider. + fireEvent.pointerDown(rowStrip, { button: 0, pointerId: 5, clientX: 40 }); + fireEvent.pointerMove(rowStrip, { pointerId: 5, clientX: 10 }); + fireEvent.pointerUp(rowStrip, { pointerId: 5, clientX: 10 }); + const resized = useLogOptions.getState().columnWidths.author; + expect(resized).toBe(160); + expect(release).toHaveBeenCalledWith(5); + + // Double-clicking the header divider drops the custom width so the column auto-fits. + const header = screen.getByRole("separator", { name: "Resize Author column" }); + fireEvent.doubleClick(header); + expect(useLogOptions.getState().columnWidths.author).toBeUndefined(); + }); + + it("a divider resizes only the two adjacent columns, not the whole table", async () => { + // Signature sits between Author and Date. Dragging the Date divider must + // widen Date and narrow Signature only — Author and Commit stay put. + useLogOptions.setState({ + showColumnHeaders: true, + showSignature: true, + showDate: true, + columnOrder: ["author", "signature", "date"], + }); + render(); + const date = await screen.findByRole("separator", { name: "Resize Date column" }); + date.setPointerCapture = vi.fn(); + date.hasPointerCapture = () => true; + date.releasePointerCapture = vi.fn(); + fireEvent.pointerDown(date, { button: 0, pointerId: 6, clientX: 100 }); + fireEvent.pointerMove(date, { pointerId: 6, clientX: 60 }); + fireEvent.pointerUp(date, { pointerId: 6, clientX: 60 }); + const widths = useLogOptions.getState().columnWidths; + expect(widths.date).toBe(180); // 140 + 40 + expect(widths.signature).toBe(60); // 100 - 40 + expect(widths.author).toBeUndefined(); // untouched + expect(widths.subject).toBeUndefined(); // flexible column untouched + }); + it("keeps pointer resizing separate from reordering and releases its capture on blur", async () => { useLogOptions.setState({ showColumnHeaders: true }); render(); @@ -187,8 +313,8 @@ describe("log controls", () => { author.setPointerCapture = vi.fn(); author.hasPointerCapture = () => true; author.releasePointerCapture = release; - fireEvent.pointerDown(author, { button: 0, pointerId: 1, clientX: 10 }); - fireEvent.pointerMove(author, { pointerId: 1, clientX: 40 }); + fireEvent.pointerDown(author, { button: 0, pointerId: 1, clientX: 40 }); + fireEvent.pointerMove(author, { pointerId: 1, clientX: 10 }); expect(useLogOptions.getState().columnWidths.author).toBe(160); fireEvent.blur(window); expect(release).toHaveBeenCalledWith(1); diff --git a/src/features/vcs/log/ColumnHeaders.tsx b/src/features/vcs/log/ColumnHeaders.tsx index 32a8b8b9b..db5154529 100644 --- a/src/features/vcs/log/ColumnHeaders.tsx +++ b/src/features/vcs/log/ColumnHeaders.tsx @@ -1,12 +1,14 @@ import { tx } from "@/platform/i18n"; -import { lockDragCursor, showContextMenu } from "@/ui"; +import { showContextMenu } from "@/ui"; import clsx from "clsx"; import { useCallback, useEffect, useRef, useState } from "react"; import styles from "../GitLog.module.css"; -import { logOptions, type LogOptions } from "../logOptions"; +import { type LogOptions } from "../logOptions"; import { updateLogOptions } from "../logStore"; import { useVcs } from "../store"; +import { ColumnResizeHandle } from "./ColumnResizeHandle"; import { SUBJECT_COLUMN, columnSequence, type LogColumn } from "./shared"; +import { columnPrev, resetColumnWidth, type ResizeTarget } from "./useColumnResize"; interface ColumnDrag { id: string; @@ -14,6 +16,16 @@ interface ColumnDrag { after: boolean; } +/** Fixed columns that can be hidden from the header context menu. */ +const HIDDEN_COLUMN_OPTION: Record = { + author: "showAuthor", + date: "showDate", + hash: "showHash", + signature: "showSignature", + "github-checks": "showGitHubChecks", + repository: "showRepository", +}; + export function ColumnHeaders({ columns, options, @@ -35,7 +47,10 @@ export function ColumnHeaders({ }; const visibleIds = ids.filter((id) => id === SUBJECT_COLUMN.id || columns.some((column) => column.id === id)); return ( -
+
{options.showRepository && useVcs.getState().roots.length > 1 && ( {tx("Repository")} )} @@ -49,6 +64,7 @@ export function ColumnHeaders({ subject={cid === SUBJECT_COLUMN.id} ids={visibleIds} options={options} + columns={columns} drag={drag} onMove={move} onDragOver={(id, target, after) => @@ -69,6 +85,7 @@ function LogColumnHeader({ subject, ids, options, + columns, drag, onMove, onDragOver, @@ -78,6 +95,7 @@ function LogColumnHeader({ subject?: boolean; ids: string[]; options: LogOptions; + columns: LogColumn[]; drag: ColumnDrag | null; onMove(source: string, target: string | null, after: boolean): void; onDragOver(id: string, target: string | null, after: boolean): void; @@ -90,26 +108,16 @@ function LogColumnHeader({ element: HTMLElement; pointerId: number; } | null>(null); - const resizeDrag = useRef<{ - x: number; - width: number; - element: HTMLElement; - pointerId: number; - releaseCursor: () => void; - } | null>(null); const cancel = useCallback(() => { - const captures = [press.current, resizeDrag.current]; + const capture = press.current; press.current = null; - resizeDrag.current?.releaseCursor(); - resizeDrag.current = null; - for (const capture of captures) - if (capture?.element.hasPointerCapture?.(capture.pointerId)) - capture.element.releasePointerCapture(capture.pointerId); + if (capture?.element.hasPointerCapture?.(capture.pointerId)) + capture.element.releasePointerCapture(capture.pointerId); onDragCancel(); }, [onDragCancel]); useEffect(() => { const escape = (e: globalThis.KeyboardEvent) => { - if (e.key !== "Escape" || (!press.current && !resizeDrag.current)) return; + if (e.key !== "Escape" || !press.current) return; e.preventDefault(); e.stopPropagation(); cancel(); @@ -123,11 +131,15 @@ function LogColumnHeader({ }; }, [cancel]); const width = options.columnWidths[column.id] ?? column.width ?? 120; - const resize = (value: number) => - updateLogOptions({ - columnWidths: { ...logOptions().columnWidths, [column.id]: Math.max(40, Math.min(800, value)) }, - }); + const resizeTarget: ResizeTarget = { + id: column.id, + width, + ...columnPrev(ids, column.id, options, columns), + // Commit is flex:1 — dragging its left divider only resizes the left neighbour. + leftOnly: subject || undefined, + }; const index = ids.indexOf(column.id); + const isFirst = index === 0; const hitColumn = (x: number, y: number) => { const el = document.elementFromPoint(x, y)?.closest?.("[data-log-column]"); if (!el || el.parentElement !== press.current?.element.parentElement) return null; @@ -183,59 +195,32 @@ function LogColumnHeader({ disabled: index === ids.length - 1, run: () => onMove(column.id, ids[index + 1] ?? null, true), }, - ...(subject ? [] : [{ label: "Reset Width", run: () => resize(column.width ?? 120) }]), + ...(subject + ? [] + : [ + { label: "Reset Width", run: () => resetColumnWidth(column.id) }, + { kind: "separator" as const }, + { + label: tx("Hide Column"), + run: () => { + const key = HIDDEN_COLUMN_OPTION[column.id]; + if (key) updateLogOptions({ [key]: false }); + }, + }, + ]), ]); }} > {tx(column.title)} - {!subject && ( - { - if (e.button !== 0) return; - e.preventDefault(); - e.stopPropagation(); - resizeDrag.current = { - x: e.clientX, - width, - element: e.currentTarget, - pointerId: e.pointerId, - releaseCursor: lockDragCursor("ew-resize"), - }; - e.currentTarget.setPointerCapture(e.pointerId); - }} - onPointerMove={(e) => { - if (resizeDrag.current && e.currentTarget.hasPointerCapture(e.pointerId)) - resize(resizeDrag.current.width + e.clientX - resizeDrag.current.x); - }} - onPointerUp={(e) => { - resizeDrag.current?.releaseCursor(); - resizeDrag.current = null; - if (e.currentTarget.hasPointerCapture(e.pointerId)) e.currentTarget.releasePointerCapture(e.pointerId); - }} - onPointerCancel={() => { - resizeDrag.current?.releaseCursor(); - resizeDrag.current = null; - }} - onLostPointerCapture={() => { - resizeDrag.current?.releaseCursor(); - resizeDrag.current = null; - }} - onKeyDown={(e) => { - if (e.key !== "ArrowLeft" && e.key !== "ArrowRight") return; - e.preventDefault(); - e.stopPropagation(); - if (e.altKey) - onMove(column.id, ids[index + (e.key === "ArrowLeft" ? -1 : 1)] ?? null, e.key === "ArrowRight"); - else resize(width + (e.key === "ArrowLeft" ? -10 : 10)); - }} + {subject ? ( + // Commit's left divider exists only in the header. It is decorative when + // Commit is the first column; otherwise it resizes the neighbour on its left. + + ) : ( + onMove(column.id, ids[index + delta] ?? null, delta === 1)} /> )} diff --git a/src/features/vcs/log/ColumnResizeHandle.tsx b/src/features/vcs/log/ColumnResizeHandle.tsx new file mode 100644 index 000000000..13f17a628 --- /dev/null +++ b/src/features/vcs/log/ColumnResizeHandle.tsx @@ -0,0 +1,49 @@ +import { tx } from "@/platform/i18n"; +import clsx from "clsx"; +import styles from "../GitLog.module.css"; +import { resizeColumnPair, useColumnResize, type ResizeTarget } from "./useColumnResize"; + +/** + * Column divider on the column's left edge. A visible rule marks the grab target; + * hovering brightens it. Keyboard users get a focusable separator whose Left/Right + * arrows resize the adjacent pair (Alt+Left/Right reorders, header only). + * + * `disabled` renders the rule without any resize interaction — used for the + * first column's left border, which has no neighbour to give/take space. + */ +export function ColumnResizeHandle({ + target, + title, + onReorder, + disabled, +}: { + target: ResizeTarget; + title: string; + onReorder?: (delta: number) => void; + disabled?: boolean; +}) { + const resize = useColumnResize(target); + return ( + { + if (disabled || (e.key !== "ArrowLeft" && e.key !== "ArrowRight")) return; + e.preventDefault(); + e.stopPropagation(); + const delta = e.key === "ArrowLeft" ? -1 : 1; + if (e.altKey && onReorder) onReorder(delta); + // Handle is on the left edge: Left arrow widens this column. + // resizeColumnPair takes positive = widen, so invert the arrow delta. + else resizeColumnPair(target, -delta * 10); + }} + /> + ); +} diff --git a/src/features/vcs/log/CommitRow.tsx b/src/features/vcs/log/CommitRow.tsx index aa585e067..fbdd87404 100644 --- a/src/features/vcs/log/CommitRow.tsx +++ b/src/features/vcs/log/CommitRow.tsx @@ -11,8 +11,10 @@ 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 { columnPrev } from "./useColumnResize"; function CommitRowView({ id, @@ -152,7 +154,12 @@ function CommitRowView({ id={id} role="option" aria-selected={selected} - className={clsx(styles.row, onBranch && styles.currentBranch, selected && styles.selected)} + className={clsx( + styles.row, + onBranch && styles.currentBranch, + selected && styles.selected, + opts.showColumnDividers && styles.showDividers, + )} style={{ top }} onMouseDown={(e) => { if (e.shiftKey) e.preventDefault(); // no text selection on range clicks @@ -168,10 +175,11 @@ function CommitRowView({ {repoName(commitRepo(c)!)} )} - {columnSequence(opts.columnOrder, columns).map((cid) => { + {columnSequence(opts.columnOrder, columns).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 ( ` : undefined} > {column.render(c)} + ); })} diff --git a/src/features/vcs/log/FilterBar.tsx b/src/features/vcs/log/FilterBar.tsx index d143317f7..fb5ab9de9 100644 --- a/src/features/vcs/log/FilterBar.tsx +++ b/src/features/vcs/log/FilterBar.tsx @@ -491,6 +491,7 @@ export function viewOptionsMenu(o: LogOptions): MenuItem[] { toggle("GitHub Commit Checks", o, "showGitHubChecks"), { kind: "separator" }, toggle("Column Headers", o, "showColumnHeaders"), + toggle("Column Dividers", o, "showColumnDividers"), ], }, { kind: "separator" }, diff --git a/src/features/vcs/log/RowResizeHandle.tsx b/src/features/vcs/log/RowResizeHandle.tsx new file mode 100644 index 000000000..acd3f856d --- /dev/null +++ b/src/features/vcs/log/RowResizeHandle.tsx @@ -0,0 +1,9 @@ +import clsx from "clsx"; +import styles from "../GitLog.module.css"; +import { useColumnResize, type ResizeTarget } from "./useColumnResize"; + +/** Full-height resize strip on a data-row cell (IDEA's column divider). */ +export function RowResizeHandle({ target }: { target: ResizeTarget }) { + const resize = useColumnResize(target); + return