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:
@@ -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"));
|
||||
|
||||
Reference in New Issue
Block a user