fix(vcs): Git Log column dividers, resize direction and Hide Column (#3879)

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>
This commit is contained in:
Muu
2026-11-17 19:43:43 +08:00
committed by GitHub
co-authored by muutot
parent 5c0ff2a918
commit 084be4fb51
11 changed files with 478 additions and 80 deletions
+69 -3
View File
@@ -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;
@@ -157,7 +157,7 @@ describe("log controls", () => {
useLogOptions.setState({ showColumnHeaders: true });
render(<LogView />);
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(<LogView />);
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(<LogView />);
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(<LogView />);
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(<LogView />);
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(
<>
<LogView />
<ContextMenuHost />
</>,
);
const author = document.querySelector<HTMLElement>('[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(<LogView />);
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<HTMLElement>('[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(<LogView />);
await screen.findByRole("separator", { name: "Resize Author column" });
const rows = within(screen.getByRole("listbox", { name: "Commits" })).getAllByRole("option");
const rowStrip = rows[0]!.querySelector<HTMLElement>('[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(<LogView />);
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(<LogView />);
@@ -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);
+55 -70
View File
@@ -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<string, keyof LogOptions> = {
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 (
<div className={clsx(styles.row, styles.columnHeader)} style={{ minWidth }}>
<div
className={clsx(styles.row, styles.columnHeader, options.showColumnDividers && styles.showDividers)}
style={{ minWidth }}
>
{options.showRepository && useVcs.getState().roots.length > 1 && (
<span className={styles.colRepository}>{tx("Repository")}</span>
)}
@@ -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 && (
<span
className={styles.columnResize}
role="separator"
aria-orientation="vertical"
aria-label={tx`Resize ${tx(column.title)} column`}
aria-valuemin={40}
aria-valuemax={800}
aria-valuenow={width}
tabIndex={0}
onPointerDown={(e) => {
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.
<ColumnResizeHandle target={resizeTarget} title={column.title} disabled={isFirst} />
) : (
<ColumnResizeHandle
target={resizeTarget}
title={column.title}
onReorder={(delta) => onMove(column.id, ids[index + delta] ?? null, delta === 1)}
/>
)}
</span>
@@ -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 (
<span
className={clsx(styles.columnResize, disabled && styles.columnResizeDisabled)}
role="separator"
aria-orientation="vertical"
aria-label={disabled ? tx`${tx(title)} column border` : tx`Resize ${tx(title)} column`}
aria-valuemin={40}
aria-valuemax={800}
aria-valuenow={target.width}
tabIndex={disabled ? -1 : 0}
{...(disabled ? {} : resize)}
onKeyDown={(e) => {
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);
}}
/>
);
}
+12 -3
View File
@@ -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)!)}
</span>
)}
{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 (
<span
key={cid}
@@ -181,10 +189,11 @@ function CommitRowView({
column.id === "author" && mine && styles.mine,
column.id === "hash" && styles.hash,
)}
style={{ width: opts.columnWidths[column.id] ?? column.width ?? 120 }}
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) }} />
</span>
);
})}
+1
View File
@@ -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" },
+9
View File
@@ -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 <span className={clsx(styles.columnResize, styles.columnResizeRow)} aria-hidden="true" {...resize} />;
}
+144
View File
@@ -0,0 +1,144 @@
import { lockDragCursor } from "@/ui";
import {
useCallback,
useEffect,
useRef,
type MouseEvent as ReactMouseEvent,
type PointerEvent as ReactPointerEvent,
} from "react";
import { logOptions, type LogOptions } from "../logOptions";
import { updateLogOptions } from "../logStore";
import { SUBJECT_COLUMN, type LogColumn } from "./shared";
const MIN_WIDTH = 40;
const MAX_WIDTH = 800;
const clamp = (value: number) => Math.max(MIN_WIDTH, Math.min(MAX_WIDTH, value));
export type ResizeTarget = {
id: string;
width: number;
/** Column to the left of this divider, or null when this is the first column. */
prevId: string | null;
prevWidth: number;
/** True for the flexible Commit column: only the left neighbour gets a stored width. */
leftOnly?: boolean;
};
/** Resolve the column immediately left of `id` in the visible order. */
export function columnPrev(
ids: string[],
id: string,
options: LogOptions,
columns: LogColumn[],
): { prevId: string | null; prevWidth: number } {
const index = ids.indexOf(id);
const prevId = index > 0 ? ids[index - 1] : null;
// The Commit column is flex:1 and absorbs space on its own — never store a width for it.
// (When *we are* the Commit column the caller handles the left neighbour via leftOnly,
// so this guard only applies to fixed columns whose left neighbour is Commit.)
if (!prevId || (prevId === SUBJECT_COLUMN.id && id !== SUBJECT_COLUMN.id)) return { prevId: null, prevWidth: 0 };
const prev = columns.find((c) => c.id === prevId);
// subject has no fixed width of its own; its "prevWidth" is unused in leftOnly mode.
return { prevId, prevWidth: options.columnWidths[prevId] ?? prev?.width ?? 120 };
}
/**
* Resize the divider between `id` (right) and `prevId` (left): only these two
* columns give/take space, so every other column stays put. When the left neighbour
* is the flexible Commit column, only the right column's width is stored (Commit
* absorbs the rest through flex:1).
*/
export function resizeColumnPair(target: ResizeTarget, delta: number) {
const { id, width, prevId, prevWidth, leftOnly } = target;
const widths = { ...logOptions().columnWidths };
if (prevId == null) {
// First column with no left neighbour (should be non-resizable at the UI layer).
widths[id] = clamp(width + delta);
} else if (leftOnly) {
// The Commit column is flex:1. The handle sits on the boundary (the left
// neighbour's right edge), so the divider follows the pointer: dragging right
// widens the left neighbour and shrinks Commit. `delta` is already -dx, so
// subtracting it makes the neighbour track dx exactly.
widths[prevId] = clamp(prevWidth - delta);
} else {
const left = clamp(prevWidth - delta);
const given = prevWidth - left; // what the left column actually gave up
widths[id] = clamp(width + given);
widths[prevId] = left;
}
updateLogOptions({ columnWidths: widths });
}
/** IDEA's double-click-on-divider behaviour: drop the custom width so the column fits its content again. */
export function resetColumnWidth(id: string) {
const widths = { ...logOptions().columnWidths };
delete widths[id];
updateLogOptions({ columnWidths: widths });
}
type Drag = ResizeTarget & {
x: number;
element: HTMLElement;
pointerId: number;
releaseCursor: () => void;
};
/**
* Pointer-driven column resize with a full-height hit strip on the column's left
* edge. Dragging left widens the column (and narrows only its left neighbour);
* the divider follows the pointer 1:1.
*/
export function useColumnResize(target: ResizeTarget) {
const drag = useRef<Drag | null>(null);
// Listeners are attached imperatively so `cancel` is defined before it is referenced.
const listeners = useRef<{ blur: () => void; escape: (e: KeyboardEvent) => void } | null>(null);
const cancel = useCallback(() => {
const d = drag.current;
if (!d) return;
d.releaseCursor();
drag.current = null;
if (d.element.hasPointerCapture?.(d.pointerId)) d.element.releasePointerCapture(d.pointerId);
if (listeners.current) {
window.removeEventListener("blur", listeners.current.blur);
window.removeEventListener("keydown", listeners.current.escape, true);
listeners.current = null;
}
}, []);
useEffect(() => () => cancel(), [cancel]);
return {
onPointerDown: (e: ReactPointerEvent<HTMLElement>) => {
if (e.button !== 0 || drag.current) return;
// Suppress the compatibility mousedown so a data-row strip doesn't select the row.
e.preventDefault();
e.stopPropagation();
const blur = () => cancel();
const escape = (ev: KeyboardEvent) => {
if (ev.key === "Escape") cancel();
};
drag.current = {
...target,
x: e.clientX,
element: e.currentTarget,
pointerId: e.pointerId,
releaseCursor: lockDragCursor("ew-resize"),
};
listeners.current = { blur, escape };
e.currentTarget.setPointerCapture?.(e.pointerId);
window.addEventListener("blur", blur);
window.addEventListener("keydown", escape, true);
},
onPointerMove: (e: ReactPointerEvent<HTMLElement>) => {
const d = drag.current;
// Handle is on the left edge: drag left -> wider.
if (d && e.currentTarget.hasPointerCapture?.(e.pointerId)) resizeColumnPair(d, -(e.clientX - d.x));
},
onPointerUp: cancel,
onPointerCancel: cancel,
onLostPointerCapture: cancel,
onMouseDown: (e: ReactMouseEvent<HTMLElement>) => e.stopPropagation(),
onDoubleClick: (e: ReactMouseEvent<HTMLElement>) => {
e.stopPropagation();
resetColumnWidth(target.id);
},
};
}
+3
View File
@@ -25,6 +25,8 @@ export interface LogOptions {
showGitHubChecks: boolean;
/** The row naming the columns, where they are resized and reordered. */
showColumnHeaders: boolean;
/** Draw a 1px divider on each column's left edge (off by default, like IDEA). */
showColumnDividers: boolean;
highlightMine: boolean;
highlightMerges: boolean;
highlightCurrentBranch: boolean;
@@ -63,6 +65,7 @@ export const DEFAULT_LOG_OPTIONS: LogOptions = {
showSignature: false,
showGitHubChecks: false,
showColumnHeaders: false,
showColumnDividers: false,
highlightMine: true,
highlightMerges: true,
highlightCurrentBranch: true,
+3
View File
@@ -2352,6 +2352,9 @@
"Search installed plugins": "Search installed plugins",
"Runs “conda create -n <name> python=<version>”: a new environment with only Python in it, in conda's envs directory; the new interpreter becomes the project interpreter.": "Runs “conda create -n <name> python=<version>”: a new environment with only Python in it, in conda's envs directory; the new interpreter becomes the project interpreter.",
"Java Agents": "Java Agents",
"Hide Column": "Hide Column",
"Column Dividers": "Column Dividers",
"{title} column border": "{title} column border",
"File at a Git revision (read-only).": "File at a Git revision (read-only).",
"Adjust colors for red-green vision deficiency is on, so this scheme shows its red-green colors.": "Adjust colors for red-green vision deficiency is on, so this scheme shows its red-green colors.",
"Appearance settings": "Appearance settings",
+4 -1
View File
@@ -8713,6 +8713,10 @@
"Run code inside the Java applications you start": "在你启动的 Java 应用中运行代码",
"Java agents of {list} were not added: they load only in local projects.": "未添加 {list} 的 Java 代理:Java 代理只加载到本地项目中。",
"Java agent": "Java 代理",
"Java Agents": "Java 代理",
"Hide Column": "隐藏该列",
"Column Dividers": "列分隔线",
"{title} column border": "{title}列边界",
"1 Pull Request": "1 个拉取请求",
"{count} Pull Requests": "{count} 个拉取请求",
"Issues": "议题",
@@ -8728,7 +8732,6 @@
"Session references and artifacts": "会话引用与制品",
"Copy Link": "复制链接",
"Add to Message": "添加到消息",
"Java Agents": "Java 代理",
"File at a Git revision (read-only).": "Git 修订版中的文件(只读)。",
"Adjust colors for red-green vision deficiency is on, so this scheme shows its red-green colors.": "已开启「针对红绿色觉缺陷调整颜色」,此方案显示的是红绿色觉变体的颜色。",
"Appearance settings": "外观设置",