дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-03 16:51:16 +02:00
At full horizontal scroll the end of a diff's longest line stayed under the change overview lane. The diff editors reserve the lane's width at the end of the content, in split and unified modes. Fixes #7228 Co-authored-by: formiat <[email protected]>
115 рядки
4.5 KiB
TypeScript
115 рядки
4.5 KiB
TypeScript
/**
|
|
* The horizontal scrollbar of a diff pane: with wrapping off and lines wider
|
|
* than the pane, it must sit at the pane's bottom edge — reachable without
|
|
* scrolling the diff content to its end — in every viewer mode.
|
|
*/
|
|
import { rmSync } from "node:fs";
|
|
import { dirname } from "node:path";
|
|
import { readSides, tempDiffRepo } from "./diffRepo";
|
|
import { expect, test } from "./fixtures";
|
|
|
|
let repo = "";
|
|
test.beforeAll(() => {
|
|
repo = tempDiffRepo();
|
|
});
|
|
test.afterAll(() => rmSync(dirname(repo), { recursive: true, force: true }));
|
|
|
|
for (const [name, options] of [
|
|
["side-by-side without alignment", { mode: "split", alignChanges: false }],
|
|
["side-by-side aligned", { mode: "split", alignChanges: true }],
|
|
["unified", { mode: "unified", alignChanges: false }],
|
|
] as const) {
|
|
test(`the horizontal scrollbar spans the pane viewport (${name})`, async ({ workbench: page }) => {
|
|
const path = "src/soft-wrap.ts";
|
|
const { left, right } = readSides(repo, path);
|
|
await page.evaluate(
|
|
async ({ path, left, right, options }) => {
|
|
localStorage.setItem("openidea.vcs.diffOptions", JSON.stringify(options));
|
|
const actions = "/src/platform/actions.ts";
|
|
const { executeAction } = await import(/* @vite-ignore */ actions);
|
|
await executeAction("diff.compareTexts", {
|
|
path,
|
|
title: path,
|
|
left: { text: left, label: "HEAD" },
|
|
right: { text: right, label: "Working tree" },
|
|
});
|
|
},
|
|
{
|
|
path,
|
|
left,
|
|
right,
|
|
options: {
|
|
...options,
|
|
ignore: "none",
|
|
highlight: "words",
|
|
collapse: true,
|
|
syncScroll: true,
|
|
softWrap: false,
|
|
},
|
|
},
|
|
);
|
|
const geometry = await page
|
|
.locator(".cm-editor.cm-merge-b")
|
|
.first()
|
|
.evaluate((ed) => {
|
|
const scroller = ed.querySelector<HTMLElement>(".cm-scroller")!;
|
|
const host = (ed.closest(".cm-mergeView") ?? ed).parentElement!;
|
|
return {
|
|
wide: scroller.scrollWidth,
|
|
clientW: scroller.clientWidth,
|
|
scrollerBottom: scroller.getBoundingClientRect().bottom,
|
|
viewportBottom: host.getBoundingClientRect().bottom,
|
|
};
|
|
});
|
|
// The lines are far wider than the pane: there is something to scroll.
|
|
expect(geometry.wide).toBeGreaterThan(geometry.clientW + 1_000);
|
|
// The scroller spans the pane's viewport, so its horizontal scrollbar is at
|
|
// the bottom edge instead of the content's end.
|
|
expect(geometry.scrollerBottom).toBeCloseTo(geometry.viewportBottom, 0);
|
|
});
|
|
}
|
|
|
|
for (const mode of ["split", "unified"] as const) {
|
|
test(`the end of the longest line clears the overview lane at the full horizontal scroll (${mode})`, async ({
|
|
workbench: page,
|
|
}) => {
|
|
const line = (word: string) => `// ${"lorem ipsum dolor sit amet ".repeat(12)}${word} line end`;
|
|
await page.evaluate(
|
|
async ({ left, right, mode }) => {
|
|
localStorage.setItem(
|
|
"openidea.vcs.diffOptions",
|
|
JSON.stringify({ mode, alignChanges: false, collapse: false, softWrap: false }),
|
|
);
|
|
const actions = "/src/platform/actions.ts";
|
|
const { executeAction } = await import(/* @vite-ignore */ actions);
|
|
await executeAction("diff.compareTexts", {
|
|
path: "src/long.ts",
|
|
title: "src/long.ts",
|
|
left: { text: left, label: "HEAD" },
|
|
right: { text: right, label: "Working tree" },
|
|
});
|
|
},
|
|
// The old line is the longest: in the unified view it decides the width as a deleted chunk.
|
|
{ left: `a\n${line("old old old")}\nb\n`, right: `a\n${line("new")}\nb\n`, mode },
|
|
);
|
|
const editor = page.locator(".cm-editor.cm-merge-b").first();
|
|
await expect(editor).toContainText("new line end");
|
|
// How far the end of the longest line reaches past the lane's left edge, scrolled fully right.
|
|
const overlap = () =>
|
|
editor.evaluate((ed) => {
|
|
const scroller = ed.querySelector<HTMLElement>(".cm-scroller")!;
|
|
scroller.scrollLeft = scroller.scrollWidth;
|
|
const lane = ed.querySelector(".cm-openidea-overview")!.getBoundingClientRect();
|
|
const ends = [...ed.querySelectorAll(".cm-line, .cm-deletedLine")]
|
|
.filter((l) => l.textContent?.endsWith("line end"))
|
|
.map((l) => {
|
|
const range = document.createRange();
|
|
range.selectNodeContents(l);
|
|
return range.getBoundingClientRect().right;
|
|
});
|
|
return Math.max(...ends) - lane.left;
|
|
});
|
|
await expect.poll(overlap).toBeLessThanOrEqual(0);
|
|
});
|
|
}
|