mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 16:04:21 +00:00
fix(vcs): fit Git Log commits to the available width (#4517)
Git Log sized its table for the widest graph row plus the saved column widths, so in a narrow pane columns went out of view behind a horizontal scrollbar. The header and rows now fit the pane: the columns shrink, the subject keeps a minimum share, and graph lanes past the room left for the subject are cut off rather than squeezed. Co-authored-by: shohruh-genius <7658451+shohruh-genius@users.noreply.github.com>
This commit is contained in:
co-authored by
shohruh-genius
parent
6e2c19846c
commit
2c8a029939
@@ -76,6 +76,47 @@ test.beforeEach(async ({ workbench: page }) => {
|
||||
});
|
||||
});
|
||||
|
||||
test("fits a wide graph and saved columns without horizontal scrolling", async ({ workbench: page }) => {
|
||||
await page.evaluate(async () => {
|
||||
const module = "/src/features/vcs/logOptions.ts";
|
||||
const { useLogOptions } = await import(/* @vite-ignore */ module);
|
||||
useLogOptions.setState({
|
||||
showColumnHeaders: true,
|
||||
showHash: true,
|
||||
showSignature: true,
|
||||
columnWidths: { author: 400, date: 240 },
|
||||
});
|
||||
});
|
||||
const list = page.getByRole("listbox", { name: "Commits" });
|
||||
await expect(list.getByRole("separator", { name: "Resize Date column" })).toBeVisible();
|
||||
|
||||
for (const width of [1400, 620, 400]) {
|
||||
await page.setViewportSize({ width, height: 900 });
|
||||
await expect
|
||||
.poll(() =>
|
||||
list.evaluate((element) => {
|
||||
const header = [...element.querySelectorAll("[data-log-column]")];
|
||||
const row = [...element.querySelector('[role="option"]')!.children];
|
||||
const right = element.getBoundingClientRect().right;
|
||||
return {
|
||||
fits: element.scrollWidth === element.clientWidth,
|
||||
aligned: header.every((cell, i) => {
|
||||
const heading = cell.getBoundingClientRect();
|
||||
const data = row[i]!.getBoundingClientRect();
|
||||
return heading.width > 0 && heading.right <= right && Math.abs(heading.right - data.right) < 1;
|
||||
}),
|
||||
};
|
||||
}),
|
||||
)
|
||||
.toEqual({ fits: true, aligned: true });
|
||||
}
|
||||
|
||||
await list.hover();
|
||||
await page.mouse.wheel(450, 450);
|
||||
await expect.poll(() => list.evaluate((element) => element.scrollTop)).toBeGreaterThan(0);
|
||||
expect(await list.evaluate((element) => element.scrollLeft)).toBe(0);
|
||||
});
|
||||
|
||||
test("keeps a wide Git graph filled during scrollbar drags and its edges interactive afterwards", async ({
|
||||
workbench: page,
|
||||
}) => {
|
||||
|
||||
@@ -168,7 +168,7 @@
|
||||
.list {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: auto;
|
||||
overflow: hidden auto;
|
||||
outline: none;
|
||||
/* Rows coming and going while scrolling relay out the list alone, not the workbench. */
|
||||
contain: strict;
|
||||
@@ -181,8 +181,8 @@
|
||||
height: 26px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-2);
|
||||
padding: 0 8px;
|
||||
gap: min(var(--space-2), 2%);
|
||||
padding: 0 min(var(--space-2), 2%);
|
||||
white-space: nowrap;
|
||||
cursor: default;
|
||||
font-size: var(--fs-ui);
|
||||
@@ -199,18 +199,18 @@
|
||||
background: var(--bg-app);
|
||||
}
|
||||
.columnCell {
|
||||
flex: none;
|
||||
flex: 0 1 auto;
|
||||
min-width: 0;
|
||||
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);
|
||||
padding-inline-start: min(var(--space-2), 2%);
|
||||
/* Anchor for the full-height column resize strip (IDEA's invisible divider). */
|
||||
position: relative;
|
||||
}
|
||||
.columnHeading {
|
||||
position: relative;
|
||||
padding-inline-end: 6px;
|
||||
cursor: grab;
|
||||
touch-action: none;
|
||||
}
|
||||
@@ -314,7 +314,7 @@
|
||||
--log-row-bg: var(--bg-tree-selected);
|
||||
}
|
||||
.colSubject {
|
||||
flex: 1;
|
||||
flex: 1 0 min(220px, 50%);
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -365,9 +365,12 @@
|
||||
}
|
||||
.graph {
|
||||
flex: none;
|
||||
/* Leave room for the subject when the graph has many lanes: the lanes past it are cut off, not squeezed. */
|
||||
max-width: calc(100% - min(120px, 50%));
|
||||
fill: none;
|
||||
stroke-width: 1.6;
|
||||
overflow: visible;
|
||||
clip-path: inset(-50% 0);
|
||||
}
|
||||
.refs {
|
||||
flex: 0 1 auto;
|
||||
@@ -760,7 +763,8 @@
|
||||
}
|
||||
|
||||
.colRepository {
|
||||
flex: 0 0 100px;
|
||||
flex: 0 1 100px;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
|
||||
@@ -26,15 +26,7 @@ const HIDDEN_COLUMN_OPTION: Record<string, keyof LogOptions> = {
|
||||
repository: "showRepository",
|
||||
};
|
||||
|
||||
export function ColumnHeaders({
|
||||
columns,
|
||||
options,
|
||||
minWidth,
|
||||
}: {
|
||||
columns: LogColumn[];
|
||||
options: LogOptions;
|
||||
minWidth: number;
|
||||
}) {
|
||||
export function ColumnHeaders({ columns, options }: { columns: LogColumn[]; options: LogOptions }) {
|
||||
const [drag, setDrag] = useState<ColumnDrag | null>(null);
|
||||
const ids = columnSequence(options.columnOrder, columns);
|
||||
const cancel = useCallback(() => setDrag(null), []);
|
||||
@@ -47,10 +39,7 @@ 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, options.showColumnDividers && styles.showDividers)}
|
||||
style={{ minWidth }}
|
||||
>
|
||||
<div className={clsx(styles.row, styles.columnHeader, options.showColumnDividers && styles.showDividers)}>
|
||||
{options.showRepository && useVcs.getState().roots.length > 1 && (
|
||||
<span className={styles.colRepository}>{tx("Repository")}</span>
|
||||
)}
|
||||
|
||||
@@ -43,7 +43,7 @@ import { currentRepo, currentRepoRoot, useVcs } from "../store";
|
||||
import { ColumnHeaders } from "./ColumnHeaders";
|
||||
import { CommitSignature } from "./CommitMessage";
|
||||
import { CommitRow } from "./CommitRow";
|
||||
import { LANE, ROW, type LogColumn, type RowEvents } from "./shared";
|
||||
import { ROW, type LogColumn, type RowEvents } from "./shared";
|
||||
|
||||
const remoteNameSets = new WeakMap<readonly string[], ReadonlySet<string>>();
|
||||
|
||||
@@ -197,15 +197,6 @@ export function CommitList() {
|
||||
),
|
||||
};
|
||||
}, [hoverColor, linear, displayedGraph, headKeys]);
|
||||
const minWidth = useMemo(
|
||||
() =>
|
||||
rows.reduce((width, row) => Math.max(width, row.width * LANE), 100) +
|
||||
columns.reduce(
|
||||
(width, column) => width + (opts.columnWidths[column.id] ?? column.width ?? 120),
|
||||
opts.showRepository && useVcs.getState().roots.length > 1 ? 220 : 120,
|
||||
),
|
||||
[rows, columns, opts.columnWidths, opts.showRepository],
|
||||
);
|
||||
const filterBranches = useGitLog((s) => s.filters.branches);
|
||||
const currentBranch = useVcs((s) => s.branch?.head ?? null);
|
||||
// Nothing to tell apart when the log is filtered to the current branch.
|
||||
@@ -581,11 +572,11 @@ export function CommitList() {
|
||||
);
|
||||
}}
|
||||
>
|
||||
{opts.showColumnHeaders && <ColumnHeaders columns={columns} options={opts} minWidth={minWidth} />}
|
||||
{opts.showColumnHeaders && <ColumnHeaders columns={columns} options={opts} />}
|
||||
{!commits.length && !loading && finished && (
|
||||
<div className={styles.message}>{headCommit ? tx("No commits match the filters") : tx("No commits yet")}</div>
|
||||
)}
|
||||
<div style={{ height: virtualizer.getTotalSize(), position: "relative", minWidth }}>
|
||||
<div style={{ height: virtualizer.getTotalSize(), position: "relative" }}>
|
||||
{items.map((v) => {
|
||||
const c = commits[v.index];
|
||||
if (!c)
|
||||
|
||||
@@ -39,6 +39,7 @@ export function GraphCell({
|
||||
interactive?: boolean;
|
||||
}) {
|
||||
const cy = ROW / 2;
|
||||
const width = row.width * LANE;
|
||||
const draw = (s: GraphSegment, i: number, up: boolean) => {
|
||||
const fromX = x(s.fromX ?? s.from);
|
||||
const toX = x(s.toX ?? s.to);
|
||||
@@ -112,7 +113,7 @@ export function GraphCell({
|
||||
return (
|
||||
<svg
|
||||
className={styles.graph}
|
||||
width={row.width * LANE}
|
||||
width={width}
|
||||
height={ROW}
|
||||
aria-label={tx("Commit graph")}
|
||||
onMouseLeave={() => onHover?.(null)}
|
||||
|
||||
Reference in New Issue
Block a user