Resize panes and drag tabs into panes

- A divider between two panes changes their sizes, with the pointer or the keyboard. A double-click gives equal sizes.
- A tab that the user drags from the tab bar to a pane replaces its content, or opens a new pane on its right or bottom side.
- The file tree menu has "Open to the right", also for PDF files and boards.
- "New tab to the right" and "New tab below" of a browser tab open a new tab with the home page beside it. They replace "Split right" and "Split down".
- New smoke test: a PDF file beside a note.
This commit is contained in:
Knotty Wyvern
2026-11-10 12:24:17 -07:00
parent 190e5bf1bc
commit 42e18b4620
15 changed files with 555 additions and 63 deletions
+98 -2
View File
@@ -1,5 +1,6 @@
// Split view with different tabs: two documents side by side, a browser tab beside a document, a browser tab that covers
// the area and then moves into a pane, the close control of a plugin pane, and the Read beside toggle, in both themes.
// Also the divider that resizes two panes, a tab that the user drags into a pane, and the new browser tab beside a browser tab.
import assert from "node:assert/strict";
import path from "node:path";
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
@@ -19,7 +20,7 @@ await runSmoke("layout/mixedSplits", async ({ page }) => {
...workspace,
browser_connect: () => "window-session",
browser_request: ({ command, args }) => {
if (command === "newTab") { const tabId = "native-" + (++next); snapshot.tabs.push({ id: tabId, profileId: "user", url: "about:blank", title: "Browser", loading: false, blocked: 0, canBack: false, canForward: false }); return { tabId }; }
if (command === "newTab") { globalThis.newTabUrls = [...(globalThis.newTabUrls || []), args.url ?? null]; const tabId = "native-" + (++next); snapshot.tabs.push({ id: tabId, profileId: "user", url: "about:blank", title: "Browser", loading: false, blocked: 0, canBack: false, canForward: false }); return { tabId }; }
if (command === "closeTab") snapshot.tabs = snapshot.tabs.filter(tab => tab.id !== args.tabId);
return structuredClone(snapshot);
},
@@ -35,6 +36,33 @@ await runSmoke("layout/mixedSplits", async ({ page }) => {
await page.getByRole("menuitem", { name: "Open to the right", exact: true }).click();
}
async function box(locator) { const value = await locator.boundingBox(); assert.ok(value, "The pane is visible"); return value; }
// A native tab drag: dragstart on the tab button, dragover at a place of the target, then the drop and dragend.
async function dragOver(source, target, where) {
const point = await target.evaluate((node, where) => {
const r = node.getBoundingClientRect();
return where === "down" ? { x: r.left + r.width / 2, y: r.bottom - 12 } : where === "right" ? { x: r.right - 12, y: r.top + r.height / 2 } : { x: r.left + r.width / 2, y: r.top + r.height / 2 };
}, where);
return source.evaluate((node, point) => {
const transfer = new DataTransfer();
node.dispatchEvent(new DragEvent("dragstart", { bubbles: true, cancelable: true, dataTransfer: transfer }));
const over = new DragEvent("dragover", { bubbles: true, cancelable: true, clientX: point.x, clientY: point.y, dataTransfer: transfer });
document.elementFromPoint(point.x, point.y).dispatchEvent(over);
globalThis.tabDrag = { node, transfer, point };
return over.defaultPrevented;
}, point);
}
async function drop() {
return page.evaluate(() => {
const { node, transfer, point } = globalThis.tabDrag;
const event = new DragEvent("drop", { bubbles: true, cancelable: true, clientX: point.x, clientY: point.y, dataTransfer: transfer });
document.elementFromPoint(point.x, point.y).dispatchEvent(event);
node.dispatchEvent(new DragEvent("dragend", { bubbles: true, clientX: point.x, clientY: point.y, dataTransfer: transfer }));
return event.defaultPrevented;
});
}
async function setMode(mode) {
await page.evaluate(async mode => { const { saveAppearance } = await import("/src/lib/theme/appearance.ts"); saveAppearance({ theme: "default", mode }); }, mode);
}
async function newBrowserTab() {
await page.evaluate(async () => { const { pluginHost } = await import("/src/lib/plugins/registry.ts"); await pluginHost.get("browser").newTab(); });
await page.locator('[data-browser-state="ready"]').last().waitFor();
@@ -102,5 +130,73 @@ await runSmoke("layout/mixedSplits", async ({ page }) => {
await pane("b.md").locator(".cm-content").waitFor();
await pane("b.md").getByRole("button", { name: "Read beside", exact: true }).click();
await pane("b.md").locator(".md-page").waitFor();
console.log(JSON.stringify({ passed: ["two documents side by side", "browser beside a document", "replaced document stays a tab", "focus by click", "plugin pane close control", "covering browser moves into a pane", "last pane releases the browser", "Read beside toggle", "light/dark screenshots"], nativeDesktop: "not tested" }, null, 2));
await pane("b.md").getByRole("button", { name: "Read beside", exact: true }).click();
// The divider between two panes changes their sizes, with the pointer and with the keyboard.
await openToRight("a.md");
await pane("a.md").locator(".cm-content").waitFor();
const divider = page.getByRole("separator", { name: "Resize panes" });
assert.equal(await divider.count(), 1);
const area = await box(page.locator(".center"));
const handle = await box(divider);
await page.mouse.move(handle.x + handle.width / 2, handle.y + handle.height / 2);
await page.mouse.down();
await page.mouse.move(handle.x + handle.width / 2 - area.width * 0.2, handle.y + handle.height / 2, { steps: 4 });
await page.mouse.up();
const narrow = await box(pane("b.md")), wide = await box(pane("a.md"));
assert.ok(Math.abs(narrow.width - area.width * 0.3) < 4, `The left pane has 30% of the area: ${narrow.width} of ${area.width}`);
assert.ok(Math.abs(wide.x - (narrow.x + narrow.width)) < 2, "The right pane starts at the divider");
assert.equal(await divider.getAttribute("aria-valuenow"), "30");
await divider.focus(); await page.keyboard.press("ArrowRight");
assert.equal(await divider.getAttribute("aria-valuenow"), "35");
for (const mode of ["light", "dark"]) {
await setMode(mode);
await divider.hover();
await page.screenshot({ path: path.join(output, `divider-${mode}.png`) });
}
await divider.dblclick();
assert.equal(await divider.getAttribute("aria-valuenow"), "50");
// A new browser tab replaces the document in the focused pane. A document tab dragged to the bottom of the browser pane
// opens below it.
await newBrowserTab();
assert.equal(await pane("a.md").count(), 0);
assert.equal(await dragOver(tab("a.md"), browserPane, "down"), true, "The browser pane takes the tab");
await page.locator('.drop-hint[data-drop-zone="down"]').waitFor();
for (const mode of ["light", "dark"]) {
await setMode(mode);
await page.screenshot({ path: path.join(output, `tab-drop-${mode}.png`) });
}
assert.equal(await drop(), true);
await pane("a.md").locator(".cm-content").waitFor();
assert.equal(await page.locator(".drop-hint").count(), 0);
const web = await box(browserPane), below = await box(pane("a.md"));
assert.ok(below.y >= web.y + web.height - 1 && Math.abs(below.x - web.x) < 2, "The document shows below the browser");
assert.equal(await page.getByRole("separator", { name: "Resize panes" }).count(), 2);
// The browser tab dragged to the document pane replaces it there, and leaves its old pane. The first browser tab is not visible.
assert.equal(await dragOver(tab("Browser").last(), pane("b.md"), "center"), true);
assert.equal(await drop(), true);
await page.waitForFunction(() => document.querySelectorAll(".document-pane").length === 2);
assert.equal(await pane("b.md").count(), 0);
assert.equal(await tab("b.md").count(), 1, "The replaced document stays open as a tab");
const moved = await box(browserPane), rest = await box(pane("a.md"));
assert.ok(rest.x >= moved.x + moved.width - 1, "The browser shows left of the document");
// A drop on the pane that shows the tab changes nothing.
assert.equal(await dragOver(tab("Browser").last(), browserPane, "center"), false);
await drop();
// "New tab to the right" of a browser tab that covers the area opens a new browser tab beside it, not a copy of the page.
await pane("a.md").getByRole("button", { name: "Close split", exact: true }).click();
await browserPane.waitFor();
assert.ok((await box(browserPane)).width > area.width - 4, "The browser covers the area");
const before = await page.evaluate(() => globalThis.newTabUrls.length);
await tab("Browser").last().click({ button: "right" });
await page.getByRole("menuitem", { name: "New tab to the right", exact: true }).click();
await page.waitForFunction(() => document.querySelectorAll(".plugin-pane.embedded:not(.inactive)").length === 2);
assert.deepEqual(await page.evaluate(start => globalThis.newTabUrls.slice(start), before), [null], "The new tab opens the home page");
const [first, second] = await page.locator(".plugin-pane.embedded:not(.inactive)").evaluateAll(nodes => nodes.map(node => { const r = node.getBoundingClientRect(); return { x: r.x, width: r.width }; }).sort((a, b) => a.x - b.x));
assert.ok(second.x >= first.x + first.width - 1 && first.width > area.width * 0.4, "The browser tabs show side by side");
await page.screenshot({ path: path.join(output, "browser-beside-browser.png") });
console.log(JSON.stringify({ passed: ["two documents side by side", "browser beside a document", "replaced document stays a tab", "focus by click", "plugin pane close control", "covering browser moves into a pane", "last pane releases the browser", "Read beside toggle", "divider by pointer, keyboard, and double-click", "tab drop below a pane", "tab drop replaces a pane", "new browser tab beside a browser tab", "light/dark screenshots"], nativeDesktop: "not tested" }, null, 2));
}, { timeout: 30000 });
@@ -51,7 +51,7 @@ await runSmoke("layout/panesAndSettings", async ({ browser }) => {
const menu = page.getByRole("menu", { name: "File actions", exact: true });
await menu.waitFor();
const labels = await menu.locator(":scope > button, :scope > hr").evaluateAll(nodes => nodes.map(node => node.tagName === "HR" ? "|" : node.querySelector(".action-label").textContent));
assert.deepEqual(labels, ["Open in new tab", "Open in default app", "Open in terminal", "|", "Cut", "Copy", "Paste", "Make a copy", "|",
assert.deepEqual(labels, ["Open in new tab", "Open to the right", "Open in default app", "Open in terminal", "|", "Cut", "Copy", "Paste", "Make a copy", "|",
"Rename", "Remove bookmark", "Pin", "Save as template", "|", "Show in Explorer", "Copy path", "|", "Undo file move", "Redo file move", "|", "Delete", "Delete permanently"]);
const error = await page.evaluate(() => { const probe = document.createElement("span"); probe.style.color = "var(--rs-error)"; document.body.append(probe); const color = getComputedStyle(probe).color; probe.remove(); return color; });
assert.equal(await menu.getByRole("menuitem", { name: "Delete", exact: true }).evaluate(node => getComputedStyle(node).color), error);
@@ -0,0 +1,84 @@
// A PDF file beside a note: "Open to the right" in the file tree opens the PDF in a new pane beside the note.
// The user writes in the note and turns the pages of the PDF, and both panes stay visible. A drag of the divider resizes
// both panes. A PDF that covers the area moves into the left pane when a note opens to its right. Both themes.
import assert from "node:assert/strict";
import path from "node:path";
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
import { samplePdf } from "../../fixtures/pdf/fixtures.mjs";
await runSmoke("layout/pdfBesideNote", async ({ page }) => {
const output = await outputDir("layout/pdfBesideNote");
await page.addInitScript(() => localStorage.setItem("runestone.settings", JSON.stringify({ autosaveEnabled: false })));
await mockTauri(page, {
state: { sample: [...samplePdf()] },
commands: test => ({
...test.workspace({ root: "C:\\pdf-beside-note", files: { "Sample.pdf": "", "note.md": "# Note\n\nReading notes.\n" } }),
plugins_snapshot: () => ({ root: "C:/plugins", plugins: [] }),
spelling_menu_install: () => null,
workspace_read_bytes: () => new Uint8Array(test.state.sample).buffer,
}),
});
const row = name => page.locator(`[data-tree-rel="${name}"]`);
const note = page.locator('[data-document-path="note.md"]');
const pdf = page.locator(".plugin-pane:not(.inactive)").filter({ has: page.locator(".pdf-viewer") });
const status = pdf.locator(".pdf-viewer .status");
async function box(locator) { const value = await locator.boundingBox(); assert.ok(value, "The pane is visible"); return value; }
async function besideEachOther(left, right, message) {
const a = await box(left), b = await box(right);
assert.ok(b.x >= a.x + a.width - 1 && Math.abs(a.y - b.y) < 2, message);
return [a, b];
}
await page.goto(smokeUrl);
await row("note.md").click();
await note.locator(".cm-content").waitFor();
// The file tree opens the PDF in a new pane to the right of the note.
await row("Sample.pdf").click({ button: "right" });
await page.getByRole("menuitem", { name: "Open to the right", exact: true }).click();
await status.filter({ hasText: /^Page 1 of 2$/ }).waitFor();
assert.equal(await page.locator(".document-pane").count(), 2);
await besideEachOther(note, pdf, "The PDF shows to the right of the note");
// Write in the note. The PDF stays visible.
await note.locator(".cm-content").click();
await page.keyboard.press("Control+End");
await page.keyboard.type("Typed beside the PDF.");
assert.match(await note.locator(".cm-content").innerText(), /Typed beside the PDF\./);
assert.equal(await pdf.count(), 1);
// Turn a page of the PDF. The note stays visible and keeps the text.
await pdf.getByRole("button", { name: "Next page", exact: true }).click();
await status.filter({ hasText: /^Page 2 of 2$/ }).waitFor();
assert.match(await note.locator(".cm-content").innerText(), /Typed beside the PDF\./);
// Back to the note: the keyboard goes to the note.
await note.locator(".cm-content").click();
await page.keyboard.type(" More.");
assert.match(await note.locator(".cm-content").innerText(), /Typed beside the PDF\. More\./);
await page.waitForFunction(() => document.querySelector('[role="tab"][aria-selected="true"]')?.textContent?.includes("note.md"));
// The divider gives the PDF more space.
const divider = page.getByRole("separator", { name: "Resize panes" });
const handle = await box(divider), area = await box(page.locator(".center"));
await page.mouse.move(handle.x + handle.width / 2, handle.y + handle.height / 2);
await page.mouse.down();
await page.mouse.move(handle.x + handle.width / 2 - area.width * 0.15, handle.y + handle.height / 2, { steps: 4 });
await page.mouse.up();
const [left, right] = await besideEachOther(note, pdf, "The panes stay side by side after a resize");
assert.ok(right.width > left.width + area.width * 0.2, "The PDF pane is wider than the note pane");
for (const mode of ["light", "dark"]) {
await page.evaluate(async mode => { const { saveAppearance } = await import("/src/lib/theme/appearance.ts"); saveAppearance({ theme: "default", mode }); }, mode);
await page.screenshot({ path: path.join(output, `pdf-beside-note-${mode}.png`) });
}
// A PDF that covers the area moves into the left pane when a note opens to its right.
await pdf.getByRole("button", { name: "Close split", exact: true }).click();
await page.getByRole("tab", { name: /Sample/ }).click();
await status.waitFor();
assert.ok((await box(pdf)).width > area.width - 4, "The PDF covers the area");
await row("note.md").click({ button: "right" });
await page.getByRole("menuitem", { name: "Open to the right", exact: true }).click();
await note.locator(".cm-content").waitFor();
await besideEachOther(pdf, note, "The PDF keeps the left pane");
console.log(JSON.stringify({ passed: ["file tree opens a PDF to the right", "typing in the note beside the PDF", "page turn in the PDF beside the note", "divider resize", "covering PDF moves into a pane", "light/dark screenshots"], nativeDesktop: "not tested" }, null, 2));
}, { timeout: 30000 });
+44 -2
View File
@@ -1,7 +1,7 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { initialDocumentPanes, syncDocumentPanes, splitDocumentPane, closeDocumentPane, selectPane, readDocumentPane, splitDocumentView, splitWithContent, showInActivePane, paneOf, releaseSolePlugin } from "../../../src/lib/workspace/documentPanes.ts";
import { paneBounds, splitSibling, stackLayout } from "../../../src/lib/workspace/splitLayout.ts";
import { initialDocumentPanes, syncDocumentPanes, splitDocumentPane, closeDocumentPane, selectPane, readDocumentPane, splitDocumentView, splitWithContent, showInActivePane, paneOf, releaseSolePlugin, dropInPane, resizeDocumentPanes } from "../../../src/lib/workspace/documentPanes.ts";
import { paneBounds, splitDividers, splitSibling, stackLayout, setSplitRatio } from "../../../src/lib/workspace/splitLayout.ts";
import { registerSelection, selectedEditorText } from "../../../src/lib/editor/selection.ts";
test("opening a link to the right keeps its source and focuses an existing pane for duplicate targets", () => {
@@ -112,3 +112,45 @@ test("the split sibling names the pane that a plugin view opened beside", () =>
assert.deepEqual(splitSibling(tree, "a"), { direction: "right", sibling: "b" });
assert.equal(splitSibling("a", "a"), null);
});
test("a divider changes the ratio of its split, within limits, and the narrow layout keeps the ratio", () => {
let state = syncDocumentPanes(initialDocumentPanes(), ["a", "b", "c"], "a");
state = splitDocumentPane(state, state.active, "b", "right");
state = splitWithContent(state, "right", { documentId: "c" }, "low", "down");
const dividers = splitDividers(state.layout);
assert.deepEqual(dividers.map(divider => [divider.path.join("/"), divider.direction, divider.ratio]), [["", "right", 0.5], ["second", "down", 0.5]]);
state = resizeDocumentPanes(state, [], 0.3);
state = resizeDocumentPanes(state, ["second"], 0.75);
const bounds = paneBounds(state.layout);
assert.equal(bounds["document-main"].width, 30);
assert.deepEqual(bounds.right, { left: 30, top: 0, width: 70, height: 75 });
assert.equal(bounds.low.top, 75);
assert.equal(paneBounds(stackLayout(state.layout))["document-main"].height, 30);
assert.equal(paneBounds(resizeDocumentPanes(state, [], 0.02).layout)["document-main"].width, 10, "A pane keeps a tenth of the split at least");
assert.equal(setSplitRatio("only", [], 0.4), "only");
assert.equal(resizeDocumentPanes(state, ["second", "first"], 0.4), state, "A path to a pane changes nothing");
});
test("a tab drop replaces the content of a pane or opens a pane beside it, and the content leaves its old pane", () => {
let state = syncDocumentPanes(initialDocumentPanes(), ["a", "b", "c"], "a");
const main = state.active;
state = splitWithContent(state, main, { pluginKey: "web" }, "right");
// A document dropped in the browser pane replaces the browser there. The browser stays open as a tab.
let next = dropInPane(state, { documentId: "b" }, "right", "center", "new");
assert.deepEqual(next.panes.map(pane => [pane.documentId, pane.pluginKey]), [["a", null], ["b", null]]);
assert.equal(next.active, "right");
// A drop on the bottom side of a pane opens a new pane there.
next = dropInPane(state, { documentId: "c" }, main, "down", "new");
assert.deepEqual(paneBounds(next.layout).new, { left: 0, top: 50, width: 50, height: 50 });
assert.equal(next.active, "new");
// A visible tab moves: its old pane closes.
next = dropInPane(state, { pluginKey: "web" }, main, "down", "new");
assert.deepEqual(next.panes.map(pane => [pane.id, pane.pluginKey]), [[main, null], ["new", "web"]]);
assert.deepEqual(paneBounds(next.layout).new, { left: 0, top: 50, width: 100, height: 50 });
next = dropInPane(state, { pluginKey: "web" }, main, "center", "new");
assert.deepEqual(next.panes.map(pane => pane.pluginKey), ["web"]);
// A drop on the pane that shows the content only makes it active.
assert.equal(dropInPane(state, { pluginKey: "web" }, "right", "down", "new").panes.length, 2);
assert.equal(dropInPane(state, { documentId: "a" }, "missing", "center", "new"), state);
});