Panes: edges dragged by the mouse side by side, and the active pane shown whole
Side by side, the mouse near an edge between two panes of a column, or between two columns, takes it (row-resize, col-resize) and drags it: down a column the same splitter as a page's, across the strip the columns' widths. Only a pinned pane's size, and the width of a column holding one, stick; the others are the layout's again once another pane is the active one. Esc puts the edge back; a double click lays it out automatically. A column whose share would cut the active pane short now stacks side by side too, as a page already did: the active pane is shown whole and the others give way. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014yB6q4BHMwptTX3YFtkRab
This commit is contained in:
1 parent
5c867b2eef
commit
a3f25fbdcc
8 files changed
+618
-84
No files matched your search
@@ -540,6 +540,10 @@ test("a pane is dragged by its grip, or its tab, up or down its column; the orde
|
||||
await page.reload();
|
||||
await page.waitForSelector(".strip .pane");
|
||||
expect((await columns(page))[1]).toEqual([kids[4], ...kids.slice(0, 4)]);
|
||||
// The active pane back in the first column, so this one shares its height again (the active pane, cut short by a share, would stack it).
|
||||
await pane(page, "Explicata").locator(".top h1, .pane-head h2").first().dispatchEvent("click");
|
||||
await expect.poll(() => page.locator(".strip > .col").nth(1).getAttribute("class")).not.toContain("crowded");
|
||||
await still(page);
|
||||
// Downward, reaching the top of a pane below is enough: the dragged pane lands after it.
|
||||
await drag(kids[4], kids[1]);
|
||||
expect((await columns(page))[1]).toEqual([kids[0], kids[1], kids[4], kids[2], kids[3]]);
|
||||
@@ -558,6 +562,150 @@ test("a pane is dragged by its grip, or its tab, up or down its column; the orde
|
||||
}
|
||||
});
|
||||
|
||||
/** The columns measured, left to right: each one's box, whether it is sized by hand, and its panes' tops and heights, whether active, and titles. */
|
||||
const measured = (page: Page) =>
|
||||
page.evaluate(() =>
|
||||
[...document.querySelectorAll<HTMLElement>(".strip > .col")].map((col) => {
|
||||
const c = col.getBoundingClientRect();
|
||||
return {
|
||||
left: c.left,
|
||||
right: c.right,
|
||||
w: c.width,
|
||||
top: c.top,
|
||||
bottom: c.bottom,
|
||||
h: col.clientHeight,
|
||||
sized: col.classList.contains("sized"),
|
||||
panes: [...col.querySelectorAll<HTMLElement>(":scope > .pane")].map((p) => {
|
||||
const r = p.getBoundingClientRect();
|
||||
return { top: r.top, h: r.height, active: p.classList.contains("active"), title: p.querySelector(".pane-head h2")?.textContent?.trim() ?? "" };
|
||||
}),
|
||||
};
|
||||
}),
|
||||
);
|
||||
/** The mouse put here: the cursor it shows. */
|
||||
async function cursorAt(page: Page, x: number, y: number) {
|
||||
await page.mouse.move(x, y);
|
||||
return page.evaluate(([x, y]) => getComputedStyle(document.elementFromPoint(x, y)!).cursor, [x, y]);
|
||||
}
|
||||
/** The mouse pressed at (x, y), moved by (dx, dy) a step at a time, then let go (unless `up` is false). */
|
||||
async function mouseDrag(page: Page, x: number, y: number, dx: number, dy: number, up = true) {
|
||||
await page.mouse.move(x, y);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(x + dx, y + dy, { steps: 8 });
|
||||
if (up) await page.mouse.up();
|
||||
await frames(page);
|
||||
}
|
||||
|
||||
test("side by side, the mouse resizes panes by their edges: the cursor says which way, the panes either side give and take, down a column and across the strip; only a pinned pane's size, and its column's width, outlive a move to another pane", async ({ page }) => {
|
||||
await open(page);
|
||||
await keys(page, "j Enter j Enter");
|
||||
await expect.poll(async () => (await columns(page))[1]?.length).toBe(2);
|
||||
await still(page);
|
||||
let [c0, c1] = await measured(page);
|
||||
const W0 = c0.w;
|
||||
const W1 = c1.w;
|
||||
const x = c1.left + c1.w / 2;
|
||||
/** A height away from the edges between the panes: the middle of the tallest. */
|
||||
const away = (c: typeof c1) => {
|
||||
const p = c.panes.reduce((a, b) => (b.h > a.h ? b : a));
|
||||
return p.top + p.h / 2;
|
||||
};
|
||||
let mid = away(c1);
|
||||
// The edge between the two panes, up and down; the column's top and foot are no edges.
|
||||
let y = c1.panes[1].top;
|
||||
expect(await cursorAt(page, x, y)).toBe("row-resize");
|
||||
expect(await cursorAt(page, x, y + 3)).toBe("row-resize");
|
||||
expect(await cursorAt(page, x, y - 3)).toBe("row-resize");
|
||||
expect(await cursorAt(page, x, y + 40)).not.toContain("resize");
|
||||
expect(await cursorAt(page, x, c1.top + 2)).not.toContain("resize");
|
||||
expect(await cursorAt(page, x, c1.bottom - 2)).not.toContain("resize");
|
||||
// The edge between the two columns, either side; the strip's outer edges are none.
|
||||
expect(await cursorAt(page, c1.left, mid)).toBe("col-resize");
|
||||
expect(await cursorAt(page, c1.left - 3, mid)).toBe("col-resize");
|
||||
expect(await cursorAt(page, c1.left + 3, mid)).toBe("col-resize");
|
||||
expect(await cursorAt(page, c1.left + 30, mid)).not.toContain("resize");
|
||||
expect(await cursorAt(page, c0.left + 2, mid)).not.toContain("resize");
|
||||
expect(await cursorAt(page, c1.right - 2, mid)).not.toContain("resize");
|
||||
|
||||
// Dragged, the edge between the panes follows the mouse: the pane on one side grows, the other gives, filling the column.
|
||||
const before = await state(page, (s) => ({ pane: s.paneAt, node: s.focus.node, grain: s.focus.grain }));
|
||||
const dir = c1.panes[0].h > c1.panes[1].h ? -1 : 1;
|
||||
await page.mouse.move(x, y);
|
||||
await page.mouse.down();
|
||||
for (const d of [30, 90, 150]) {
|
||||
await page.mouse.move(x, y + dir * d, { steps: 2 });
|
||||
await frames(page);
|
||||
const now = (await measured(page))[1];
|
||||
expect(now.sized).toBe(true);
|
||||
expect(Math.abs(now.panes[1].top - (y + dir * d)), `at ${dir * d}`).toBeLessThanOrEqual(1.5);
|
||||
expect(Math.abs(now.panes[0].h + now.panes[1].h - now.h)).toBeLessThanOrEqual(1);
|
||||
}
|
||||
await page.mouse.up();
|
||||
await frames(page);
|
||||
c1 = (await measured(page))[1];
|
||||
expect(Math.abs(c1.panes[1].top - (y + dir * 150))).toBeLessThanOrEqual(1.5);
|
||||
// The press was not a click: the active pane and the focus are as they were, and no text was selected.
|
||||
expect(await state(page, (s) => ({ pane: s.paneAt, node: s.focus.node, grain: s.focus.grain }))).toEqual(before);
|
||||
expect(await page.evaluate(() => window.getSelection()?.isCollapsed ?? true)).toBe(true);
|
||||
// Esc while dragging puts the edge back.
|
||||
y = c1.panes[1].top;
|
||||
await mouseDrag(page, x, y, 0, dir * 80, false);
|
||||
expect(Math.abs((await measured(page))[1].panes[1].top - (y + dir * 80))).toBeLessThanOrEqual(1.5);
|
||||
await page.keyboard.press("Escape");
|
||||
await page.mouse.up();
|
||||
await frames(page);
|
||||
expect(Math.abs((await measured(page))[1].panes[1].top - y)).toBeLessThanOrEqual(1.5);
|
||||
|
||||
// The edge between the columns: the column before takes what the one after gives.
|
||||
mid = away(c1);
|
||||
await mouseDrag(page, c1.left, mid, 120, 0);
|
||||
[c0, c1] = await measured(page);
|
||||
expect(Math.abs(c0.w - (W0 + 120))).toBeLessThanOrEqual(1);
|
||||
expect(Math.abs(c1.w - (W1 - 120))).toBeLessThanOrEqual(1);
|
||||
expect(Math.abs(c1.left - c0.right)).toBeLessThanOrEqual(1);
|
||||
expect(await state(page, (s) => s.paneAt)).toBe(before.pane);
|
||||
await expect(page.locator(".panes[data-edge]")).toHaveCount(1);
|
||||
await page.mouse.move(x + 60, mid + 100);
|
||||
await expect(page.locator(".panes[data-edge]")).toHaveCount(0);
|
||||
|
||||
// Nothing pinned: the focus moved to another pane (the one opened from the focused row), the column and the strip are laid out automatically again.
|
||||
expect(c0.panes[0].active).toBe(true);
|
||||
await keys(page, "Alt+l");
|
||||
await expect.poll(async () => (await measured(page))[1].panes.some((p) => p.active)).toBe(true);
|
||||
await expect.poll(async () => (await measured(page))[1].sized).toBe(false);
|
||||
[c0, c1] = await measured(page);
|
||||
expect(Math.abs(c0.w - W0)).toBeLessThanOrEqual(1);
|
||||
expect(Math.abs(c1.w - W1)).toBeLessThanOrEqual(1);
|
||||
|
||||
// The first pane pinned (by its pin: the active pane stays), then both edges dragged: once the focus moves, its height and its column's width stay; the other pane has the rest of the column, the other column its own width.
|
||||
await pane(page, c1.panes[0].title).locator(".pane-ctl .pane-btn.pin").click();
|
||||
await expect(pane(page, c1.panes[0].title)).toHaveClass(/pinned/);
|
||||
await still(page);
|
||||
c1 = (await measured(page))[1];
|
||||
const dir2 = c1.panes[0].h > c1.panes[1].h ? -1 : 1;
|
||||
await mouseDrag(page, x, c1.panes[1].top, 0, dir2 * 120);
|
||||
mid = away((await measured(page))[1]);
|
||||
await mouseDrag(page, c1.left, mid, -80, 0);
|
||||
[c0, c1] = await measured(page);
|
||||
expect(c1.sized).toBe(true);
|
||||
expect(Math.abs(c1.w - (W1 + 80))).toBeLessThanOrEqual(1);
|
||||
const kept = c1.panes[0].h;
|
||||
const back = c1.panes.findIndex((p) => !p.active);
|
||||
await keys(page, back === 0 ? "[" : "]");
|
||||
await expect.poll(async () => (await measured(page))[1].panes[back].active).toBe(true);
|
||||
await still(page);
|
||||
[c0, c1] = await measured(page);
|
||||
expect(c1.sized).toBe(true);
|
||||
expect(Math.abs(c1.panes[0].h - kept)).toBeLessThanOrEqual(1);
|
||||
expect(Math.abs(c1.panes[1].h - (c1.h - kept))).toBeLessThanOrEqual(1);
|
||||
expect(Math.abs(c1.w - (W1 + 80))).toBeLessThanOrEqual(1);
|
||||
expect(Math.abs(c0.w - W0)).toBeLessThanOrEqual(1);
|
||||
|
||||
// A double click on the edge: the column laid out automatically again.
|
||||
await page.mouse.dblclick(x, c1.panes[1].top);
|
||||
await expect.poll(async () => (await measured(page))[1].sized).toBe(false);
|
||||
});
|
||||
|
||||
test("a pinned pane is not covered in its column, and outlives a closed parent as an orphan in its column", async ({ page }) => {
|
||||
const kids = await five(page);
|
||||
// Pin the second fork, by its button: it opens beside the focused one and stays open as the focus moves up and down the column.
|
||||
@@ -770,3 +918,23 @@ test("in the column a Shift open is a plain open, and the status line says why o
|
||||
await keys(page, "[");
|
||||
await expect(page.locator(".status .message")).toContainText("panes view");
|
||||
});
|
||||
|
||||
test("side by side, a crowded column's edges resize too: the column is laid out by hand from what showed of each pane, one under another, the tabs kept", async ({ page }) => {
|
||||
await five(page);
|
||||
await expect(page.locator(".strip > .col").nth(1)).toHaveClass(/crowded/);
|
||||
let c = (await measured(page))[1];
|
||||
const x = c.left + c.w / 2;
|
||||
const n = c.panes.length;
|
||||
// Between two tabs stuck at the column's top, and where the pane shown whole begins: edges.
|
||||
expect(await cursorAt(page, x, c.panes[2].top)).toBe("row-resize");
|
||||
const y = c.panes[n - 1].top;
|
||||
expect(await cursorAt(page, x, y)).toBe("row-resize");
|
||||
const shown = c.panes.map((p, i) => (i < n - 1 ? c.panes[i + 1].top : c.bottom) - p.top);
|
||||
await mouseDrag(page, x, y, 0, 200);
|
||||
c = (await measured(page))[1];
|
||||
expect(c.sized).toBe(true);
|
||||
expect(Math.abs(c.panes[n - 1].top - (y + 200))).toBeLessThanOrEqual(1.5);
|
||||
expect(Math.abs(c.panes[n - 2].h - (shown[n - 2] + 200))).toBeLessThanOrEqual(1.5);
|
||||
for (let i = 0; i < n - 2; i++) expect(Math.abs(c.panes[i].h - shown[i])).toBeLessThanOrEqual(1.5);
|
||||
for (let i = 1; i < n; i++) expect(Math.abs(c.panes[i].top - (c.panes[i - 1].top + c.panes[i - 1].h))).toBeLessThanOrEqual(1);
|
||||
});
|
||||
+65
-3
@@ -1,7 +1,8 @@
|
||||
/**
|
||||
* The panes view: a click anywhere in a pane makes it active and anywhere clears a
|
||||
* selection; a column's panes stand in the order of their sources; every pane in a crowded column
|
||||
* shows at least its tab, above or below; a pane cut off for any reason peeks out whole; the curves
|
||||
* shows at least its tab, above or below; the active pane is never cut short by its share of a
|
||||
* column; a pane cut off for any reason peeks out whole; the curves
|
||||
* keep to their sources and landing lines through every kind of layout change (curveFaults); the
|
||||
* selection bar keeps clear of a tab; a dotted curve turns toward its source; Alt with h j k l moves
|
||||
* between panes. Same build, mock model and mock Wikipedia as the others.
|
||||
@@ -142,6 +143,67 @@ test("every pane of a crowded column shows at least its tab, above or below the
|
||||
expect(stubs).toBe(0);
|
||||
});
|
||||
|
||||
test("the active pane is never cut short by its share of a column: the others give way, folding to their tabs, as its Wikipedia card arrives; once the active pane is elsewhere, the column shares again", async ({ page }) => {
|
||||
await library(page);
|
||||
await clickOpen(page, "Library", "Octopus minds");
|
||||
await clickOpen(page, "Octopus minds", "A separate experiment");
|
||||
await clickOpen(page, "Octopus minds", "A body with many minds");
|
||||
await clickOpen(page, "A body with many minds", "Counting neurons");
|
||||
// A definition beside it, active: its line and then, once it has arrived, the article's card.
|
||||
await clickOpen(page, "A separate experiment", "cephalopod", ".lnk, .anchor");
|
||||
await page.mouse.move(5, 500);
|
||||
/** The panes of the column holding Counting neurons: what each needs, its height, what shows of it. */
|
||||
const column = () =>
|
||||
pane(page, "Counting neurons").evaluate((el) => {
|
||||
const col = el.parentElement!;
|
||||
const c = col.getBoundingClientRect();
|
||||
const ps = [...col.querySelectorAll<HTMLElement>(":scope > .pane")];
|
||||
return {
|
||||
crowded: col.classList.contains("crowded"),
|
||||
h: c.height,
|
||||
panes: ps.map((p, i) => {
|
||||
const r = p.getBoundingClientRect();
|
||||
const sc = getComputedStyle(p.querySelector(".pane-scroll")!);
|
||||
return {
|
||||
t: p.querySelector(".pane-head h2, .top h1")?.textContent?.trim(),
|
||||
active: p.classList.contains("active"),
|
||||
height: r.height,
|
||||
shown: Math.min(ps[i + 1]?.getBoundingClientRect().top ?? Infinity, c.bottom) - Math.max(r.top, c.top),
|
||||
need: p.querySelector<HTMLElement>(".pane-body")!.offsetHeight + parseFloat(sc.paddingTop) + parseFloat(sc.paddingBottom),
|
||||
};
|
||||
}),
|
||||
};
|
||||
});
|
||||
/** The active pane shows all it needs, up to the column less a tab for each other pane; every other pane shows at least its tab. */
|
||||
const whole = async (label: string) => {
|
||||
await still(page);
|
||||
await expect
|
||||
.poll(async () => {
|
||||
const c = await column();
|
||||
const a = c.panes.find((p) => p.active)!;
|
||||
return a.shown >= Math.min(a.need, c.h - (c.panes.length - 1) * TAB) - 2 && c.panes.every((p) => p.shown >= TAB - 1);
|
||||
}, label)
|
||||
.toBe(true);
|
||||
};
|
||||
await whole("the definition active");
|
||||
let c = await column();
|
||||
expect(c.panes.map((p) => p.t)).toEqual(["“cephalopod”", "Counting neurons"]);
|
||||
// Its card is in (it needs more than half the column, which an even share would give it), and the column stacks to show it whole.
|
||||
expect(c.panes[0].need).toBeGreaterThan(c.h / 2);
|
||||
expect(c.crowded).toBe(true);
|
||||
await noFaults(page, "the definition active");
|
||||
// The other pane active: it is the one shown whole.
|
||||
await pane(page, "Counting neurons").locator(".pane-head h2").dispatchEvent("click");
|
||||
await whole("Counting neurons active");
|
||||
// The active pane in another column: this one shares its height as before, each pane what it needs or an even share.
|
||||
await pane(page, "A body with many minds").locator(".pane-head h2").dispatchEvent("click");
|
||||
await still(page);
|
||||
c = await column();
|
||||
expect(c.crowded).toBe(false);
|
||||
for (const p of c.panes) expect(p.height, p.t).toBeGreaterThanOrEqual(Math.min(p.need, c.h / 2) - 2);
|
||||
await noFaults(page, "the active pane elsewhere");
|
||||
});
|
||||
|
||||
test("a pane cut off for any reason peeks out whole, across and down, and the curves follow it: covered from below or above, by its share, by the column's foot, beside a pinned pane, and with its column covered", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 1920, height: 700 });
|
||||
await library(page);
|
||||
@@ -210,13 +272,13 @@ test("a pane cut off for any reason peeks out whole, across and down, and the cu
|
||||
expect(await col.evaluate((c) => c.hasAttribute("data-covered") || !!c.nextElementSibling?.hasAttribute("data-over"))).toBe(true);
|
||||
expect(await sweep("column covered", true)).toBeGreaterThan(0);
|
||||
|
||||
// By its share of a column that is not crowded: a tall window, two top-level trees, one longer than its share.
|
||||
// By its share of a column that is not crowded: a tall window, two top-level trees, one longer than its share, the active pane in another column (the active one is never cut short by its share).
|
||||
await page.setViewportSize({ width: 1920, height: 1080 });
|
||||
await page.evaluate(() => Object.keys(localStorage).filter((k) => k.startsWith("ie:view:")).forEach((k) => localStorage.removeItem(k)));
|
||||
await library(page);
|
||||
await clickOpen(page, "Library", "Explicata");
|
||||
await clickOpen(page, "Library", "Octopus minds");
|
||||
await pane(page, "Octopus minds").locator(".pane-head h2").dispatchEvent("click");
|
||||
await pane(page, "Library").locator(".top h1").dispatchEvent("click");
|
||||
await still(page);
|
||||
expect(await page.locator(".strip > .col").nth(1).evaluate((c) => c.classList.contains("crowded"))).toBe(false);
|
||||
expect(await sweep("by share", false)).toBeGreaterThan(0);
|
||||
|
||||
Reference in new issue
Block a user