дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-06 10:07:11 +02:00
Fast mouse drags could hit-test, redraw the selection and recalculate edge scrolling several times before the editor painted a frame. The first move now responds immediately, later moves in the same frame share one update, and releasing the button applies the last pending position (patch to @codemirror/view).
100 рядки
4.3 KiB
TypeScript
100 рядки
4.3 KiB
TypeScript
import { expect, openFromTree, test } from "./fixtures";
|
|
|
|
test("middle and Alt drags create editable rectangles without changing ordinary selection", async ({
|
|
workbench: page,
|
|
}) => {
|
|
await openFromTree(page, "build.gradle.kts");
|
|
const text = "alpha = 111;\nbravo = 222;\ncharl = 333;\ndelta = 444;";
|
|
const prepare = () =>
|
|
page.evaluate(async (text) => {
|
|
const controllerModule = "/src/editor/core/controller.ts";
|
|
const columnModule = "/src/editor/core/cm/columnMode.ts";
|
|
const { editorController } = await import(/* @vite-ignore */ controllerModule);
|
|
const { setColumnMode } = await import(/* @vite-ignore */ columnModule);
|
|
const view = editorController().activeSlot.view;
|
|
view.dispatch({
|
|
changes: { from: 0, to: view.state.doc.length, insert: text },
|
|
selection: { anchor: 0 },
|
|
effects: setColumnMode.of(false),
|
|
});
|
|
view.focus();
|
|
const a = view.coordsAtPos(0);
|
|
const b = view.coordsAtPos(view.state.doc.line(4).from + 5);
|
|
return {
|
|
from: { x: a.left + 0.5, y: (a.top + a.bottom) / 2 },
|
|
to: { x: b.left + 0.5, y: (b.top + b.bottom) / 2 },
|
|
};
|
|
}, text);
|
|
const selection = () =>
|
|
page.evaluate(async () => {
|
|
const controllerModule = "/src/editor/core/controller.ts";
|
|
const columnModule = "/src/editor/core/cm/columnMode.ts";
|
|
const { editorController } = await import(/* @vite-ignore */ controllerModule);
|
|
const { isColumnMode } = await import(/* @vite-ignore */ columnModule);
|
|
const view = editorController().activeSlot.view;
|
|
return {
|
|
ranges: view.state.selection.ranges.map((r: { from: number; to: number }) => view.state.sliceDoc(r.from, r.to)),
|
|
columnMode: isColumnMode(view.state),
|
|
text: view.state.doc.toString(),
|
|
};
|
|
});
|
|
for (const button of ["middle", "left"] as const) {
|
|
const points = await prepare();
|
|
if (button === "left") await page.keyboard.down("Alt");
|
|
await page.mouse.move(points.from.x, points.from.y);
|
|
await page.mouse.down({ button });
|
|
await page.mouse.move(points.to.x, points.to.y, { steps: 5 });
|
|
await page.mouse.up({ button });
|
|
if (button === "left") await page.keyboard.up("Alt");
|
|
await expect.poll(async () => (await selection()).ranges).toEqual(["alpha", "bravo", "charl", "delta"]);
|
|
expect((await selection()).columnMode).toBe(false);
|
|
}
|
|
await page.keyboard.insertText("name");
|
|
await expect.poll(async () => (await selection()).text).toBe("name = 111;\nname = 222;\nname = 333;\nname = 444;");
|
|
const points = await prepare();
|
|
await page.mouse.move(points.from.x, points.from.y);
|
|
await page.mouse.down();
|
|
await page.mouse.move(points.to.x, points.to.y, { steps: 5 });
|
|
await page.mouse.up();
|
|
await expect.poll(async () => (await selection()).ranges).toEqual([text.slice(0, text.lastIndexOf("delta") + 5)]);
|
|
});
|
|
|
|
test("rapid text drags paint the latest selection and keep the endpoint on release", async ({ workbench: page }) => {
|
|
await openFromTree(page, "build.gradle.kts");
|
|
const result = await page.evaluate(async () => {
|
|
const controllerModule = "/src/editor/core/controller.ts";
|
|
const { editorController } = await import(/* @vite-ignore */ controllerModule);
|
|
const view = editorController().activeSlot.view;
|
|
view.dispatch({ selection: { anchor: 0 } });
|
|
view.focus();
|
|
const mouse = (type: string, offset: number) => {
|
|
const rect = view.coordsAtPos(offset);
|
|
view.contentDOM.dispatchEvent(
|
|
new MouseEvent(type, {
|
|
bubbles: true,
|
|
cancelable: true,
|
|
detail: 1,
|
|
clientX: rect.left + 0.1,
|
|
clientY: (rect.top + rect.bottom) / 2,
|
|
buttons: type === "mouseup" ? 0 : 1,
|
|
}),
|
|
);
|
|
};
|
|
mouse("mousedown", 5);
|
|
const heads = new Set<number>();
|
|
for (const offset of [6, 7, 8, 9]) {
|
|
mouse("mousemove", offset);
|
|
heads.add(view.state.selection.main.head);
|
|
}
|
|
await new Promise(requestAnimationFrame);
|
|
const painted = view.state.selection.main.head;
|
|
mouse("mousemove", 4);
|
|
mouse("mousemove", 2);
|
|
mouse("mouseup", 2);
|
|
const { anchor, head } = view.state.selection.main;
|
|
await new Promise(requestAnimationFrame);
|
|
return { updates: heads.size, painted, anchor, head, settled: view.state.selection.main.head };
|
|
});
|
|
expect(result).toEqual({ updates: 1, painted: 9, anchor: 5, head: 2, settled: 2 });
|
|
});
|