Порівняти коміти

..
Автор SHA1 Повідомлення Дата
l0ng-ai 56d9788747 fix(vcs): scroll the changes tree horizontally instead of clipping rows
Rows in the Commit and Local Changes trees were locked to the pane width and
ellipsized, so the end of a long file name and its directory path could only
be read by widening the tool window. The tree now keeps rows at their natural
width and scrolls horizontally, as the Project view does.

Fixes #6080
2026-11-26 16:10:01 +08:00
5 змінених файлів з 59 додано та 192 видалено

No files matched your search

+1
Переглянути файл
@@ -1130,6 +1130,7 @@ export function ChangesTree({ mode, amended }: { mode: "commit" | "local" | "dia
>
<Tree<ChangeNode>
handleRef={treeRef}
horizontalScroll
roots={roots}
getKey={(n) => n.key}
getLabel={nodeText}
+48
Переглянути файл
@@ -0,0 +1,48 @@
import { render, screen } from "@testing-library/react";
import { beforeEach, describe, expect, it, vi } from "vitest";
vi.mock("@/platform/ipc", async (importOriginal) => {
const real = await importOriginal<typeof import("@/platform/ipc")>();
return { ...real, call: vi.fn() };
});
vi.mock("../DiffEditor", () => ({ DiffEditor: () => <div /> }));
import { ChangesTree } from "../CommitView";
import { useVcs } from "../store";
import { useProject } from "@/platform/project";
const NAME = "some_long_service_implementation_with_a_very_long_name.ts";
describe("changes tree width (#6080)", () => {
beforeEach(() => {
localStorage.clear();
useProject.setState({
project: { name: "p", root: "/p", trusted: true, isGit: true, settings: {} } as never,
settings: {} as never,
});
useVcs.setState({
root: "/p",
repo: "/p",
roots: ["/p"],
status: [
{
path: `/p/src/features/some_long_module_name/${NAME}`,
relPath: `src/features/some_long_module_name/${NAME}`,
staged: null,
unstaged: "modified" as const,
renamedFrom: null,
},
],
});
});
it.each(["commit", "local"] as const)("scrolls horizontally in %s mode instead of clipping rows", (mode) => {
render(<ChangesTree mode={mode} />);
const tree = screen.getByRole("tree", { name: "Changes" });
// The rows keep their natural width and the tree tracks the widest one for its scroll range.
expect(tree.querySelector("[data-content-width]")).not.toBeNull();
const row = screen.getByText(NAME).closest("[data-row]") as HTMLElement;
expect(row.className).toMatch(/wideRow/);
});
});
+2 -83
Переглянути файл
@@ -1,9 +1,8 @@
import { describe, expect, it, vi } from "vitest";
import { Chunk, MergeView } from "@codemirror/merge";
import { EditorState, Text } from "@codemirror/state";
import { EditorView } from "@codemirror/view";
import { Text } from "@codemirror/state";
import type { EditorView } from "@codemirror/view";
import { bandAt, bandPath, transferY, PaddedPanes, UnalignedPanes, type Band } from "../diffScroll";
import { collapsedDiffLines } from "../collapsedDiffLines";
import { readFileSync } from "node:fs";
import { resolve } from "node:path";
@@ -178,32 +177,6 @@ describe("synchronized navigation scrolling", () => {
vi.useRealTimers();
}
});
it("keeps the wheel-scrolled pane in charge when the follower pane adjusts scrollTop on measure", () => {
vi.useFakeTimers();
const frame = vi.spyOn(window, "requestAnimationFrame").mockReturnValue(1);
const p = panes();
try {
p.b.scrollDOM.dispatchEvent(new Event("wheel"));
p.scroll(p.b, 1200);
expect(p.a.scrollDOM.scrollTop).toBe(1200);
// Repeated wheel events must not cancel native momentum with scrollTo(instant).
p.b.scrollDOM.dispatchEvent(new Event("wheel"));
expect(p.b.scrollDOM.scrollTo).not.toHaveBeenCalled();
// Follower shifts from CodeMirror height measurement must not yank the wheel source back.
p.scroll(p.a, 800);
expect(p.b.scrollDOM.scrollTop).toBe(1200);
expect(p.a.scrollDOM.scrollTop).toBe(1200);
// Pointer interaction on the other pane hands control back immediately.
p.a.scrollDOM.dispatchEvent(new Event("pointerdown"));
p.scroll(p.a, 400);
expect(p.b.scrollDOM.scrollTop).toBe(400);
} finally {
p.controller.destroy();
frame.mockRestore();
vi.useRealTimers();
}
});
});
describe("padded pane scrolling (aligned diff)", () => {
@@ -268,60 +241,6 @@ describe("padded pane scrolling (aligned diff)", () => {
vi.useRealTimers();
}
});
it("keeps the wheel-scrolled pane in charge when the follower shifts during layout", () => {
vi.useFakeTimers();
const p = panes();
try {
p.b.scrollDOM.dispatchEvent(new Event("wheel"));
p.scroll(p.b, 900);
expect(p.a.scrollDOM.scrollTop).toBe(900);
p.scroll(p.a, 500);
expect(p.b.scrollDOM.scrollTop).toBe(900);
expect(p.a.scrollDOM.scrollTop).toBe(900);
vi.advanceTimersByTime(150);
p.scroll(p.a, 200);
expect(p.b.scrollDOM.scrollTop).toBe(200);
} finally {
p.controller.destroy();
vi.useRealTimers();
}
});
});
describe("collapsed diff lines", () => {
it("defers button DOM replacement from docViewUpdate into CodeMirror's measure write phase", () => {
const parent = document.createElement("div");
document.body.appendChild(parent);
const view = new EditorView({
state: EditorState.create({ doc: "a\nb\nc", extensions: [collapsedDiffLines()] }),
parent,
});
const measureSpy = vi.spyOn(view, "requestMeasure");
try {
const row = document.createElement("div");
row.className = "cm-collapsedLines";
row.textContent = "10 unchanged lines";
view.contentDOM.appendChild(row);
const plugin = (
view as unknown as { plugins: Array<{ value: { docViewUpdate?: () => void } | null }> }
).plugins.find((p) => typeof p.value?.docViewUpdate === "function");
expect(plugin).toBeDefined();
measureSpy.mockClear();
plugin!.value!.docViewUpdate!();
// Must not mutate DOM synchronously during docViewUpdate (triggers WebKit scrollTop clamping).
expect(row.querySelector("button")).toBeNull();
expect(measureSpy).toHaveBeenCalledTimes(1);
const req = measureSpy.mock.calls[0]![0] as { write?: (v: unknown, view: EditorView) => void };
req.write?.(null, view);
expect(row.querySelector("button")).not.toBeNull();
expect(row.querySelector("button")?.textContent).toBe("10 unchanged lines");
} finally {
measureSpy.mockRestore();
view.destroy();
parent.remove();
}
});
});
describe("divider arrows", () => {
+2 -7
Переглянути файл
@@ -20,13 +20,8 @@ const collapseButtons = ViewPlugin.define((view) => {
row.replaceChildren(button);
}
};
// Defer DOM replacement into CodeMirror's measure write phase rather than mutating synchronously
// during docViewUpdate: in WebKit, inserting the inline SVG while updated viewport gaps have not
// flushed layout yet causes scrollTop to clamp backwards and trap wheel scrolling in a loop.
const measure = { key: enhance, read: () => null, write: enhance };
const schedule = () => view.requestMeasure(measure);
schedule();
return { docViewUpdate: schedule };
view.requestMeasure({ read: () => null, write: enhance });
return { docViewUpdate: enhance };
});
export function collapsedDiffLines(): Extension {
+6 -102
Переглянути файл
@@ -193,25 +193,17 @@ export interface DiffPanes {
* of the content, out of reach until the diff is scrolled to its end.
*/
export class PaddedPanes implements DiffPanes {
readonly extension: Extension;
readonly extension: Extension = [];
private mv: MergeView | null = null;
private sync: boolean;
private scrolling: Side | null = null;
private scrollTimer: ReturnType<typeof setTimeout> | undefined;
private wheelLeader: Side | null = null;
private wheelTimer: ReturnType<typeof setTimeout> | undefined;
/** The scroll position a pane was last moved to by the other one, to tell its echo from the user. */
private readonly moved: Record<Side, number | null> = { a: null, b: null };
private readonly cleanup: (() => void)[] = [];
constructor(sync: boolean) {
this.sync = sync;
this.extension = EditorView.updateListener.of((u) => {
if (u.heightChanged && !u.docChanged && this.mv) {
const side: Side | null = u.view === this.mv.a ? "a" : u.view === this.mv.b ? "b" : null;
if (side && this.moved[side] !== null) this.moved[side] = u.view.scrollDOM.scrollTop;
}
});
}
attach(mv: MergeView) {
@@ -219,22 +211,8 @@ export class PaddedPanes implements DiffPanes {
for (const side of ["a", "b"] as const) {
const el = this.view(side).scrollDOM;
const onScroll = () => this.scrolled(side);
const onWheel = () => {
this.interruptScroll();
this.leadWheel(side);
};
const onPointer = () => {
this.interruptScroll();
this.clearWheel();
};
el.addEventListener("scroll", onScroll, { passive: true });
el.addEventListener("wheel", onWheel, { passive: true });
el.addEventListener("pointerdown", onPointer);
this.cleanup.push(() => {
el.removeEventListener("scroll", onScroll);
el.removeEventListener("wheel", onWheel);
el.removeEventListener("pointerdown", onPointer);
});
this.cleanup.push(() => el.removeEventListener("scroll", onScroll));
}
this.resync();
}
@@ -247,14 +225,12 @@ export class PaddedPanes implements DiffPanes {
setSync(on: boolean) {
if (on === this.sync) return;
this.interruptScroll();
this.clearWheel();
this.sync = on;
this.resync();
}
scrollTo(side: Side, options: ScrollToOptions) {
this.interruptScroll();
this.clearWheel();
this.scrolling = this.sync ? side : null;
this.releaseScroll();
this.view(side).scrollDOM.scrollTo(options);
@@ -265,14 +241,12 @@ export class PaddedPanes implements DiffPanes {
* other pane's delayed reflow follows it instead of being mistaken for a user scroll pulling back.
*/
leadScroll(side: Side) {
this.clearWheel();
this.scrolling = this.sync ? side : null;
this.releaseScroll();
}
destroy() {
clearTimeout(this.scrollTimer);
clearTimeout(this.wheelTimer);
for (const f of this.cleanup) f();
this.mv = null;
}
@@ -288,16 +262,6 @@ export class PaddedPanes implements DiffPanes {
this.releaseScroll();
return;
}
if (this.wheelLeader) {
this.moved[from] = null;
if (from === this.wheelLeader) {
this.leadWheel(from);
if (this.sync) this.follow(from);
} else if (this.sync) {
this.follow(this.wheelLeader);
}
return;
}
const el = this.view(from).scrollDOM;
const moved = this.moved[from];
const echo = moved !== null && Math.abs(el.scrollTop - moved) <= 1;
@@ -305,17 +269,6 @@ export class PaddedPanes implements DiffPanes {
if (!echo && this.sync) this.follow(from);
}
private leadWheel(side: Side) {
this.wheelLeader = this.sync ? side : null;
clearTimeout(this.wheelTimer);
if (this.wheelLeader) this.wheelTimer = setTimeout(() => (this.wheelLeader = null), 150);
}
private clearWheel() {
this.wheelLeader = null;
clearTimeout(this.wheelTimer);
}
private follow(from: Side) {
const to: Side = from === "a" ? "b" : "a";
const el = this.view(to).scrollDOM;
@@ -361,8 +314,6 @@ export class UnalignedPanes implements DiffPanes {
private sync: boolean;
private scrolling: Side | null = null;
private scrollTimer: ReturnType<typeof setTimeout> | undefined;
private wheelLeader: Side | null = null;
private wheelTimer: ReturnType<typeof setTimeout> | undefined;
private frame = -1;
private resize: ResizeObserver | null = null;
private readonly cleanup: (() => void)[] = [];
@@ -375,19 +326,7 @@ export class UnalignedPanes implements DiffPanes {
opts.initialRatio != null && Number.isFinite(opts.initialRatio)
? Math.min(MAX_RATIO, Math.max(MIN_RATIO, opts.initialRatio))
: loadRatio();
this.extension = [
gapMarks,
changedLineGutters,
EditorView.updateListener.of((u) => {
// When CodeMirror's measure adjusts a follower pane's scrollTop after line heights resolve,
// update the expected echo so the layout adjustment is not mistaken for a user scroll.
if (u.heightChanged && !u.docChanged && this.mv) {
const side: Side | null = u.view === this.mv.a ? "a" : u.view === this.mv.b ? "b" : null;
if (side && this.moved[side].top !== null) this.moved[side].top = u.view.scrollDOM.scrollTop;
}
this.schedule();
}),
];
this.extension = [gapMarks, changedLineGutters, EditorView.updateListener.of(() => this.schedule())];
this.divider.className = "cm-diffDivider";
// A lone arrow is centred in the divider; a pair keeps to the two edges.
this.divider.classList.toggle("cm-diffDivider-lone", !!opts.arrows && opts.arrows.toA !== opts.arrows.toB);
@@ -410,20 +349,13 @@ export class UnalignedPanes implements DiffPanes {
for (const side of ["a", "b"] as const) {
const el = this.view(side).scrollDOM;
const onScroll = () => this.scrolled(side);
const onWheel = () => {
this.interruptScroll();
this.leadWheel(side);
};
const onPointer = () => {
this.interruptScroll();
this.clearWheel();
};
const onPointer = () => this.interruptScroll();
el.addEventListener("scroll", onScroll, { passive: true });
el.addEventListener("wheel", onWheel, { passive: true });
el.addEventListener("wheel", onPointer, { passive: true });
el.addEventListener("pointerdown", onPointer);
this.cleanup.push(() => {
el.removeEventListener("scroll", onScroll);
el.removeEventListener("wheel", onWheel);
el.removeEventListener("wheel", onPointer);
el.removeEventListener("pointerdown", onPointer);
});
}
@@ -496,7 +428,6 @@ export class UnalignedPanes implements DiffPanes {
const onWheel = (e: WheelEvent) => {
e.preventDefault();
this.interruptScroll();
this.leadWheel("b");
mv.b.scrollDOM.scrollBy(e.deltaX, e.deltaY);
};
this.divider.addEventListener("wheel", onWheel, { passive: false });
@@ -528,30 +459,17 @@ export class UnalignedPanes implements DiffPanes {
setSync(on: boolean) {
if (on === this.sync) return;
this.interruptScroll();
this.clearWheel();
this.sync = on;
this.resync();
}
scrollTo(side: Side, options: ScrollToOptions) {
this.interruptScroll();
this.clearWheel();
this.scrolling = this.sync ? side : null;
this.releaseScroll();
this.view(side).scrollDOM.scrollTo(options);
}
private leadWheel(side: Side) {
this.wheelLeader = this.sync ? side : null;
clearTimeout(this.wheelTimer);
if (this.wheelLeader) this.wheelTimer = setTimeout(() => (this.wheelLeader = null), 150);
}
private clearWheel() {
this.wheelLeader = null;
clearTimeout(this.wheelTimer);
}
private releaseScroll() {
clearTimeout(this.scrollTimer);
if (this.scrolling) this.scrollTimer = setTimeout(() => (this.scrolling = null), 150);
@@ -569,7 +487,6 @@ export class UnalignedPanes implements DiffPanes {
destroy() {
clearTimeout(this.scrollTimer);
clearTimeout(this.wheelTimer);
if (this.frame >= 0) cancelAnimationFrame(this.frame);
this.resize?.disconnect();
for (const f of this.cleanup) f();
@@ -601,19 +518,6 @@ export class UnalignedPanes implements DiffPanes {
this.schedule();
return;
}
if (this.wheelLeader) {
// Keep the actively wheel-scrolled pane in charge so follower measure adjustments never pull it back.
const moved = this.moved[side];
moved.top = moved.left = null;
if (side === this.wheelLeader) {
this.leadWheel(side);
if (this.sync) this.follow(side);
} else if (this.sync) {
this.follow(this.wheelLeader);
}
this.schedule();
return;
}
const el = this.view(side).scrollDOM;
const moved = this.moved[side];
const echo =