дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 17:47:08 +02:00
The editor could scroll horizontally past the end of the longest line without end, because the scroll-hold spacer kept growing. It is now clamped to the content's scroll width. Closes #7270 Co-authored-by: Inf1mum <[email protected]>
106 рядки
4.3 KiB
TypeScript
106 рядки
4.3 KiB
TypeScript
import type { Page } from "@playwright/test";
|
|
import { expect, test } from "./fixtures";
|
|
|
|
// Regression tests for #7270 (spacer must never extend scrollWidth on right-edge overscroll or
|
|
// fractional scrollLeft) and #6624 / #6865 (spacer must still hold scrollLeft when a line-end hint
|
|
// temporarily disappears).
|
|
|
|
async function openLongFile(page: Page, text: string) {
|
|
const path = "/dev/acme-api/src/LongLine.ts";
|
|
await page.evaluate(
|
|
async ({ path, text }) => {
|
|
const backend = "/src/editor/core/backend.ts";
|
|
(await import(/* @vite-ignore */ backend)).docBackend().files.set(path, text);
|
|
const service = "/src/workbench/contributions.ts";
|
|
await (await import(/* @vite-ignore */ service)).editorService().openFile(path);
|
|
},
|
|
{ path, text },
|
|
);
|
|
const scroller = page.locator(".cm-scroller").first();
|
|
await expect(scroller).toBeVisible();
|
|
return scroller;
|
|
}
|
|
|
|
test("right-edge elastic overscroll does not grow scrollWidth (#7270)", async ({ workbench: page }) => {
|
|
const scroller = await openLongFile(page, `${"x".repeat(300)}\n`);
|
|
await expect(page.locator(".cm-content")).toContainText("xxxxxxxxxx");
|
|
|
|
const result = await scroller.evaluate((el) => {
|
|
const startWidth = el.scrollWidth;
|
|
const cw = el.clientWidth;
|
|
const widths: number[] = [];
|
|
for (let i = 0; i < 5; i++) {
|
|
const overscrolled = el.scrollWidth - cw + 20;
|
|
Object.defineProperty(el, "scrollLeft", { configurable: true, get: () => overscrolled, set: () => {} });
|
|
el.dispatchEvent(new Event("scroll"));
|
|
widths.push(el.scrollWidth);
|
|
}
|
|
delete (el as unknown as Record<string, unknown>).scrollLeft;
|
|
return { startWidth, cw, widths };
|
|
});
|
|
|
|
expect(result.startWidth).toBeGreaterThan(result.cw);
|
|
expect(result.widths).toEqual(Array(5).fill(result.startWidth));
|
|
});
|
|
|
|
test("fractional scrollLeft at the right edge does not ratchet scrollWidth (#7270)", async ({ workbench: page }) => {
|
|
const scroller = await openLongFile(page, `${"x".repeat(300)}\n`);
|
|
await expect(page.locator(".cm-content")).toContainText("xxxxxxxxxx");
|
|
|
|
const result = await scroller.evaluate((el) => {
|
|
const startWidth = el.scrollWidth;
|
|
const cw = el.clientWidth;
|
|
const widths: number[] = [];
|
|
for (let i = 0; i < 5; i++) {
|
|
const fractional = el.scrollWidth - cw + 0.5;
|
|
Object.defineProperty(el, "scrollLeft", { configurable: true, get: () => fractional, set: () => {} });
|
|
el.dispatchEvent(new Event("scroll"));
|
|
widths.push(el.scrollWidth);
|
|
}
|
|
delete (el as unknown as Record<string, unknown>).scrollLeft;
|
|
return { startWidth, widths };
|
|
});
|
|
|
|
expect(result.widths).toEqual(Array(5).fill(result.startWidth));
|
|
});
|
|
|
|
test("still holds horizontal scroll position when a line-end hint disappears (#6624)", async ({ workbench: page }) => {
|
|
const scroller = await openLongFile(page, `${"x".repeat(200)}\n`);
|
|
await expect(page.locator(".cm-content")).toContainText("xxxxxxxxxx");
|
|
|
|
const result = await scroller.evaluate((el) => {
|
|
const baseWidth = el.scrollWidth;
|
|
// Simulate a line-end hint widening the scroller's overflow range without changing .cm-content.
|
|
const hint = document.createElement("div");
|
|
hint.style.position = "absolute";
|
|
hint.style.top = "0";
|
|
hint.style.left = `${baseWidth}px`;
|
|
hint.style.width = "300px";
|
|
hint.style.height = "1px";
|
|
hint.style.pointerEvents = "none";
|
|
el.appendChild(hint);
|
|
|
|
const widthWithHint = el.scrollWidth;
|
|
// Scroll into the region that only exists because of the line-end hint.
|
|
el.scrollLeft = widthWithHint - el.clientWidth - 40;
|
|
el.dispatchEvent(new Event("scroll"));
|
|
const scrollBefore = el.scrollLeft;
|
|
|
|
// Remove the line-end hint, as happens on an edit: scrollLeft must stay put.
|
|
hint.remove();
|
|
const scrollWhileAway = el.scrollLeft;
|
|
|
|
// Scrolling back to 0 releases the hold so the scroll range shrinks back to baseWidth.
|
|
el.scrollLeft = 0;
|
|
el.dispatchEvent(new Event("scroll"));
|
|
const widthAfterReturn = el.scrollWidth;
|
|
|
|
return { baseWidth, clientWidth: el.clientWidth, widthWithHint, scrollBefore, scrollWhileAway, widthAfterReturn };
|
|
});
|
|
|
|
expect(result.widthWithHint).toBeGreaterThan(result.baseWidth);
|
|
expect(result.scrollBefore).toBeGreaterThan(result.baseWidth - result.clientWidth);
|
|
expect(result.scrollWhileAway).toBe(result.scrollBefore);
|
|
expect(result.widthAfterReturn).toBe(result.baseWidth);
|
|
});
|