Show different tabs side by side in split view
Each tab menu has "Open to the right". It shows the tab in a new pane to the right of the active pane. A pane shows a document or a plugin tab, for example a browser tab. - A plugin view stays in the plugin layer above the panes, so a move between panes does not mount it again. - A browser tab that covers the area moves to the left pane when a tab opens beside it. The last pane gives its plugin tab the whole area. - The "Split" toggle of a document is now "Read beside". Card 565874b2.
This commit is contained in:
@@ -80,11 +80,11 @@ export function settle(page) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Choose "Write", "Source", or "Read" in the view control of a document pane, or toggle "Split" (src/lib/layout/ViewModes.svelte).
|
||||
* Choose "Write", "Source", or "Read" in the view control of a document pane, or toggle "Read beside" (src/lib/layout/ViewModes.svelte).
|
||||
* `scope` is the page, or a pane locator when the window shows more than one document pane.
|
||||
*/
|
||||
export async function chooseView(scope, name) {
|
||||
if (name === "Split") return scope.locator(".chrome-bar").getByRole("button", { name: "Split", exact: true }).click();
|
||||
if (name === "Read beside") return scope.locator(".chrome-bar").getByRole("button", { name: "Read beside", exact: true }).click();
|
||||
return scope.getByRole("radiogroup", { name: "View", exact: true }).getByRole("radio", { name, exact: true }).click();
|
||||
}
|
||||
|
||||
|
||||
@@ -103,11 +103,11 @@ await runSmoke('appearance/backgroundFrames', async ({ browser }) => {
|
||||
assert.deepEqual(await background.boundingBox(), beforeScroll);
|
||||
await page.screenshot({ path: `${output}/${theme}-reader.png` });
|
||||
// Split shows the Write editor beside Read.
|
||||
await chooseView(page, 'Split');
|
||||
await chooseView(page, 'Read beside');
|
||||
await page.locator('.live-writer .cm-content').waitFor();
|
||||
assert.equal(await style(page.locator('.live-writer .cm-editor').first(), 'backgroundColor'), 'rgba(0, 0, 0, 0)');
|
||||
await page.screenshot({ path: `${output}/${theme}-split.png` });
|
||||
await chooseView(page, 'Split');
|
||||
await chooseView(page, 'Read beside');
|
||||
await chooseView(page, 'Source');
|
||||
await page.locator('.source-editor .cm-content').waitFor();
|
||||
await page.screenshot({ path: `${output}/${theme}-ide.png` });
|
||||
|
||||
@@ -62,7 +62,7 @@ await runSmoke("find/typing", async ({ page }) => {
|
||||
await page.locator(".md-page > .reading").focus();
|
||||
}, reading);
|
||||
await chooseView(page, "Source");
|
||||
await chooseView(page, "Split");
|
||||
await chooseView(page, "Read beside");
|
||||
await typing("Split, the text side", async () => { await page.locator(".source-editor .cm-content").click(); });
|
||||
await typing("Split, the reading side", async () => { await page.locator(".md-page > .reading").click({ position: { x: 40, y: 10 } }); }, reading);
|
||||
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
// 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.
|
||||
import assert from "node:assert/strict";
|
||||
import path from "node:path";
|
||||
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("layout/mixedSplits", async ({ page }) => {
|
||||
const output = await outputDir("layout/mixedSplits");
|
||||
await page.addInitScript(() => localStorage.setItem("runestone.settings", JSON.stringify({ autosaveEnabled: false })));
|
||||
await mockTauri(page, {
|
||||
commands: test => {
|
||||
const workspace = test.workspace({
|
||||
root: "C:\\mixed-split-workspace",
|
||||
files: { "a.md": "# Alpha\n\nAlpha text.\n", "b.md": "# Bravo\n\nBravo text.\n" },
|
||||
});
|
||||
const snapshot = { profiles: [{ id: "user", name: "User" }], tabs: [], bookmarks: [], settings: { search: "duckduckgo", adblock: true, linkDestination: "internal", personalRules: "", homepage: "", filterLists: [] } };
|
||||
let next = 0;
|
||||
return {
|
||||
...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 === "closeTab") snapshot.tabs = snapshot.tabs.filter(tab => tab.id !== args.tabId);
|
||||
return structuredClone(snapshot);
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
const pane = rel => page.locator(`[data-document-path="${rel}"]`);
|
||||
const browserPane = page.locator(".plugin-pane:not(.inactive)").filter({ has: page.locator('[data-browser-state="ready"]') });
|
||||
const tab = name => page.getByRole("tab", { name: new RegExp(name) });
|
||||
async function openToRight(name) {
|
||||
await tab(name).click({ button: "right" });
|
||||
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; }
|
||||
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();
|
||||
}
|
||||
|
||||
await page.goto(smokeUrl);
|
||||
await page.locator('[data-tree-rel="a.md"]').click(); await pane("a.md").locator(".cm-content").waitFor();
|
||||
// A click in the file tree replaces the current tab, so the second file opens from a new tab.
|
||||
await page.getByRole("button", { name: "New tab (Ctrl+T)", exact: true }).click();
|
||||
await page.locator('[data-tree-rel="b.md"]').click(); await pane("b.md").locator(".cm-content").waitFor();
|
||||
assert.equal(await page.getByRole("tab").count(), 2);
|
||||
await page.waitForFunction(async () => { const { pluginHost } = await import("/src/lib/plugins/registry.ts"); return !!pluginHost.get("browser"); });
|
||||
|
||||
// Two different documents side by side.
|
||||
await openToRight("a.md");
|
||||
await pane("a.md").locator(".cm-content").waitFor();
|
||||
assert.equal(await page.locator(".document-pane").count(), 2);
|
||||
const left = await box(pane("b.md")), right = await box(pane("a.md"));
|
||||
assert.ok(right.x >= left.x + left.width - 1 && Math.abs(left.y - right.y) < 2, "The documents show side by side");
|
||||
assert.equal(await pane("a.md").locator(".breadcrumb").innerText(), "a.md", "A pane beside another pane names its file");
|
||||
await tab("a.md").click({ button: "right" });
|
||||
assert.equal(await page.getByRole("menuitem", { name: "Open to the right", exact: true }).isDisabled(), true, "A visible tab cannot open again");
|
||||
await page.keyboard.press("Escape");
|
||||
|
||||
// A new browser tab opens in the focused pane. The document that it replaces stays open as a tab.
|
||||
await newBrowserTab();
|
||||
assert.equal(await pane("a.md").count(), 0);
|
||||
assert.equal(await tab("a.md").count(), 1);
|
||||
const documentBox = await box(pane("b.md")), webBox = await box(browserPane);
|
||||
assert.ok(webBox.x >= documentBox.x + documentBox.width - 1, "The browser shows beside the document");
|
||||
assert.ok(Math.abs(webBox.width - documentBox.width) < 4, "The panes share the area");
|
||||
for (const theme of ["light", "dark"]) {
|
||||
await page.evaluate(async mode => { const { saveAppearance } = await import("/src/lib/theme/appearance.ts"); saveAppearance({ theme: "default", mode }); }, theme);
|
||||
await page.screenshot({ path: path.join(output, `document-and-browser-${theme}.png`) });
|
||||
}
|
||||
|
||||
// A click in the document pane makes its tab active. The browser stays visible.
|
||||
await pane("b.md").locator(".cm-content").click();
|
||||
await page.waitForFunction(() => document.querySelector('[role="tab"][aria-selected="true"]')?.textContent?.includes("b.md"));
|
||||
assert.equal(await browserPane.count(), 1);
|
||||
// The document opens beside the browser, and the close control of the browser pane leaves the tab open.
|
||||
await openToRight("a.md");
|
||||
await pane("a.md").locator(".cm-content").waitFor();
|
||||
assert.equal(await page.locator(".document-pane").count(), 3);
|
||||
await browserPane.getByRole("button", { name: "Close split", exact: true }).click();
|
||||
assert.equal(await page.locator(".document-pane").count(), 2);
|
||||
assert.equal(await page.getByRole("tab", { name: /Browser/ }).count(), 1);
|
||||
await pane("a.md").getByRole("button", { name: "Close split", exact: true }).click();
|
||||
assert.equal(await page.locator(".document-pane").count(), 1);
|
||||
|
||||
// A browser tab that covers the whole area moves into the left pane when a document opens to the right.
|
||||
await page.getByRole("tab", { name: /Browser/ }).click();
|
||||
await browserPane.waitFor();
|
||||
assert.ok((await box(browserPane)).width > (await box(page.locator(".center"))).width - 4, "The browser covers the area");
|
||||
await openToRight("a.md");
|
||||
await pane("a.md").locator(".cm-content").waitFor();
|
||||
const coverLeft = await box(browserPane), coverRight = await box(pane("a.md"));
|
||||
assert.ok(coverRight.x >= coverLeft.x + coverLeft.width - 1, "The browser keeps the left pane");
|
||||
await pane("a.md").getByRole("button", { name: "Close split", exact: true }).click();
|
||||
await browserPane.waitFor();
|
||||
assert.ok((await box(browserPane)).width > (await box(page.locator(".center"))).width - 4, "The last pane gives the browser the whole area");
|
||||
|
||||
// Read beside is the toggle for the Read view beside the editor.
|
||||
await tab("b.md").click();
|
||||
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));
|
||||
}, { timeout: 30000 });
|
||||
@@ -21,7 +21,7 @@ await runSmoke("layout/viewModes", async ({ browser }) => {
|
||||
const page = await openPage(context), settings = await openPage(context);
|
||||
const group = page.getByRole("radiogroup", { name: "View", exact: true });
|
||||
const radio = name => group.getByRole("radio", { name, exact: true });
|
||||
const split = page.locator(".chrome-bar").getByRole("button", { name: "Split", exact: true });
|
||||
const split = page.locator(".chrome-bar").getByRole("button", { name: "Read beside", exact: true });
|
||||
const checked = () => group.getByRole("radio", { checked: true }).getAttribute("aria-label");
|
||||
const status = () => page.locator(".status").innerText();
|
||||
async function open(name) {
|
||||
@@ -86,7 +86,7 @@ await runSmoke("layout/viewModes", async ({ browser }) => {
|
||||
await page.locator(".live-writer").waitFor();
|
||||
|
||||
// Split shows Read beside the current editor. Write and Source keep it. Read ends it.
|
||||
await chooseView(page, "Split");
|
||||
await chooseView(page, "Read beside");
|
||||
assert.equal(await split.getAttribute("aria-pressed"), "true");
|
||||
await page.locator(".body.split .live-writer").waitFor();
|
||||
await page.locator(".body.split .md-page").waitFor();
|
||||
@@ -97,10 +97,10 @@ await runSmoke("layout/viewModes", async ({ browser }) => {
|
||||
assert.equal(await split.getAttribute("aria-pressed"), "false");
|
||||
assert.equal(await page.locator(".body.split").count(), 0);
|
||||
assert.equal(await page.locator(".editor-wrap").isVisible(), false);
|
||||
await chooseView(page, "Split");
|
||||
await chooseView(page, "Read beside");
|
||||
await page.locator(".body.split .source-editor").waitFor();
|
||||
assert.equal(await checked(), "Source");
|
||||
await chooseView(page, "Split");
|
||||
await chooseView(page, "Read beside");
|
||||
await chooseView(page, "Write");
|
||||
|
||||
// The file title shows by default. The General setting hides it in Write and Read.
|
||||
@@ -123,9 +123,9 @@ await runSmoke("layout/viewModes", async ({ browser }) => {
|
||||
await page.evaluate(async mode => { const { saveAppearance } = await import("/src/lib/theme/appearance.ts"); saveAppearance({ theme: "default", mode }); window.dispatchEvent(new Event("focus")); }, theme);
|
||||
await page.waitForFunction(mode => document.documentElement.dataset.theme === mode, theme);
|
||||
await page.locator(".chrome-bar").screenshot({ path: `${output}/bar-${theme}.png` });
|
||||
await chooseView(page, "Split");
|
||||
await chooseView(page, "Read beside");
|
||||
await page.locator(".chrome-bar").screenshot({ path: `${output}/bar-split-${theme}.png` });
|
||||
await chooseView(page, "Split");
|
||||
await chooseView(page, "Read beside");
|
||||
}
|
||||
|
||||
// The controls show icons only, at every width (UI-056). The names stay for assistive technology and tooltips.
|
||||
|
||||
@@ -72,7 +72,7 @@ await runSmoke("layout/workbench", async ({ page }) => {
|
||||
await page.keyboard.press("Control+s");
|
||||
await page.waitForFunction(expected => window.__TEST__.files.get("notes/welcome.md") === expected, original + "Added in source.");
|
||||
|
||||
await chooseView(page, "Split");
|
||||
await chooseView(page, "Read beside");
|
||||
await page.locator(".md-page h1").first().waitFor();
|
||||
assert.ok(await page.locator(".source-editor").isVisible());
|
||||
await page.evaluate(() => {
|
||||
@@ -153,7 +153,7 @@ await runSmoke("layout/workbench", async ({ page }) => {
|
||||
await page.locator(".md-page").evaluate(element => { element.scrollTop = 0; });
|
||||
await page.screenshot({ path: path.join(output, "reader-narrow.png") });
|
||||
assert.ok(await page.locator(".md-page").evaluate(element => element.scrollWidth <= element.clientWidth + 1));
|
||||
await chooseView(page, "Split");
|
||||
await chooseView(page, "Read beside");
|
||||
await page.waitForFunction(() => {
|
||||
const host = document.querySelector(".source-editor");
|
||||
const rendered = host?.querySelector(".cm-editor");
|
||||
@@ -168,7 +168,7 @@ await runSmoke("layout/workbench", async ({ page }) => {
|
||||
await page.screenshot({ path: path.join(output, "reader-split-wide.png") });
|
||||
|
||||
// A second press ends the Split view.
|
||||
await chooseView(page, "Split");
|
||||
await chooseView(page, "Read beside");
|
||||
await page.locator(".md-page").waitFor({ state: "detached" });
|
||||
// The editor stores one line break character. The saved file keeps its own line breaks.
|
||||
assert.equal(await contents(), showcase.replace(/\r\n/g, "\n"));
|
||||
|
||||
@@ -118,11 +118,11 @@ await runSmoke("links/sectionLinks", async ({ page }) => {
|
||||
await readerHeadingAtTop('macOS installer (Apple Silicon)');
|
||||
await page.locator('.md-page').evaluate(node => { node.scrollTop = 0; });
|
||||
await readerJump('Linux setup', 'Linux (Intel/AMD 64-bit)');
|
||||
await chooseView(page, 'Split');
|
||||
await chooseView(page, 'Read beside');
|
||||
await page.locator('.md-page').evaluate(node => { node.scrollTop = 0; });
|
||||
await readerJump('Windows setup', 'Windows installer');
|
||||
await page.screenshot({ path:`${output}/split-${theme}-${width}.png` });
|
||||
await chooseView(page, 'Split');
|
||||
await chooseView(page, 'Read beside');
|
||||
await chooseView(page, 'Source');
|
||||
await page.locator('.source-editor .cm-content').waitFor();
|
||||
await chooseView(page, 'Read');
|
||||
|
||||
@@ -129,7 +129,7 @@ await runSmoke("tables/formulas", async ({ page }) => {
|
||||
await page.keyboard.press('Control+e');
|
||||
assert.equal(await result(3, 1).innerText(), '12');
|
||||
assert.equal(await result(3, 3).innerText(), '58');
|
||||
for (const mode of ['Read', 'Split']) {
|
||||
for (const mode of ['Read', 'Read beside']) {
|
||||
await chooseView(page, mode);
|
||||
const preview = page.locator('.md-page table').first();
|
||||
await preview.waitFor();
|
||||
@@ -146,7 +146,7 @@ await runSmoke("tables/formulas", async ({ page }) => {
|
||||
assert.match(await total.innerText(), /=SUM\(D2:D3\)/);
|
||||
assert.match(await total.innerText(), /=SUM\(B2:B3\)/);
|
||||
await shot('formulas-off-split');
|
||||
await chooseView(page, 'Split');
|
||||
await chooseView(page, 'Read beside');
|
||||
await table.waitFor();
|
||||
assert.equal(await table.locator('.md-table-formula').count(), 0);
|
||||
assert.match(await cell(3, 3).innerText(), /=SUM\(D2:D3\)/);
|
||||
|
||||
@@ -59,7 +59,7 @@ await runSmoke("tabs/menus", async ({ page }) => {
|
||||
const view = async name => {
|
||||
await show("d.md");
|
||||
await item("View").click();
|
||||
await page.getByRole(name === "Split" ? "menuitemcheckbox" : "menuitemradio", { name, exact: true }).click();
|
||||
await page.getByRole(name === "Read beside" ? "menuitemcheckbox" : "menuitemradio", { name, exact: true }).click();
|
||||
};
|
||||
await show("d.md");
|
||||
await item("View").click();
|
||||
@@ -68,11 +68,11 @@ await runSmoke("tabs/menus", async ({ page }) => {
|
||||
await page.keyboard.press("Escape");
|
||||
await view("Read");
|
||||
await page.locator(".md-page").waitFor();
|
||||
await view("Split");
|
||||
await view("Read beside");
|
||||
await page.locator(".body.split .md-page").waitFor();
|
||||
await view("Source");
|
||||
await page.locator(".body.split .source-editor .cm-content").waitFor();
|
||||
await view("Split");
|
||||
await view("Read beside");
|
||||
await page.locator(".md-page").waitFor({ state: "detached" });
|
||||
await view("Write");
|
||||
await page.locator(".live-writer .cm-editor").waitFor();
|
||||
|
||||
@@ -65,9 +65,9 @@ await runSmoke("tabs/scroll", async ({ page }) => {
|
||||
await roundTrip('.cm-scroller', 'Writing');
|
||||
await chooseView(page, 'Read');
|
||||
await roundTrip('.md-page', 'Reading');
|
||||
await chooseView(page, 'Split');
|
||||
await chooseView(page, 'Read beside');
|
||||
await roundTrip('.md-page', 'Split preview');
|
||||
await chooseView(page, 'Split');
|
||||
await chooseView(page, 'Read beside');
|
||||
await chooseView(page, 'Source');
|
||||
await page.getByRole('tab', { name: 'scroll-b.md', exact: true }).click();
|
||||
await chooseView(page, 'Source');
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { initialDocumentPanes, syncDocumentPanes, splitDocumentPane, closeDocumentPane, selectPane, readDocumentPane, splitDocumentView } from "../../../src/lib/workspace/documentPanes.ts";
|
||||
import { paneBounds } from "../../../src/lib/workspace/splitLayout.ts";
|
||||
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 { 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", () => {
|
||||
@@ -71,3 +71,44 @@ test("selection readers remain available in both panes and disposal cannot clear
|
||||
assert.equal(selectedEditorText("b"), "");
|
||||
replacement();
|
||||
});
|
||||
|
||||
test("a pane shows a document or a plugin view, and each tab has at most one pane", () => {
|
||||
let state = syncDocumentPanes(initialDocumentPanes(), ["a", "b"], "a");
|
||||
const primary = state.active;
|
||||
state = splitWithContent(state, primary, { pluginKey: "browser" }, "web");
|
||||
assert.deepEqual(state.panes.map(pane => [pane.documentId, pane.pluginKey]), [["a", null], [null, "browser"]]);
|
||||
assert.equal(state.active, "web");
|
||||
assert.equal(splitWithContent(state, primary, { pluginKey: "browser" }, "again"), selectPane(state, "web"));
|
||||
// A document change does not remove the plugin pane.
|
||||
assert.equal(syncDocumentPanes(state, ["a", "b"], null), state);
|
||||
// A selected document replaces the view of the active pane. The view stays open as a tab.
|
||||
const replaced = syncDocumentPanes(state, ["a", "b"], "b");
|
||||
assert.deepEqual(replaced.panes.map(pane => [pane.documentId, pane.pluginKey]), [["a", null], ["b", null]]);
|
||||
// A plugin view replaces the document of the active pane, and a shown document selects its pane.
|
||||
state = showInActivePane(selectPane(replaced, primary), { pluginKey: "board" });
|
||||
assert.deepEqual(state.panes.map(pane => [pane.documentId, pane.pluginKey]), [[null, "board"], ["b", null]]);
|
||||
assert.equal(showInActivePane(state, { documentId: "b" }).active, "web");
|
||||
assert.equal(paneOf(state, { pluginKey: "board" })?.id, primary);
|
||||
});
|
||||
|
||||
test("a closed plugin view leaves its pane, and the last pane gives its plugin view back to the whole area", () => {
|
||||
let state = syncDocumentPanes(initialDocumentPanes(), ["a"], "a");
|
||||
state = splitWithContent(state, state.active, { pluginKey: "browser" }, "web", "down");
|
||||
assert.deepEqual(paneBounds(state.layout).web, { left: 0, top: 50, width: 100, height: 50 });
|
||||
assert.deepEqual(paneBounds(stackLayout({ direction: "right", first: "x", second: "y" })).y, { left: 0, top: 50, width: 100, height: 50 });
|
||||
const closed = syncDocumentPanes(state, ["a"], null, []);
|
||||
assert.deepEqual(closed.panes.map(pane => pane.id), ["document-main"]);
|
||||
const remaining = closeDocumentPane(state, "document-main");
|
||||
assert.equal(remaining.active, "web");
|
||||
const released = releaseSolePlugin(remaining);
|
||||
assert.equal(released.pluginKey, "browser");
|
||||
assert.deepEqual([released.state.panes[0].documentId, released.state.panes[0].pluginKey], [null, null]);
|
||||
assert.equal(releaseSolePlugin(closed).state, closed);
|
||||
});
|
||||
|
||||
test("the split sibling names the pane that a plugin view opened beside", () => {
|
||||
const tree = { direction: "right" as const, first: "a", second: { direction: "down" as const, first: "b", second: "c" } };
|
||||
assert.deepEqual(splitSibling(tree, "c"), { direction: "down", sibling: "b" });
|
||||
assert.deepEqual(splitSibling(tree, "a"), { direction: "right", sibling: "b" });
|
||||
assert.equal(splitSibling("a", "a"), null);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user