Phase 5-3. - One radio group shows Write, Source, and Read at all times, with an icon and a name. Narrow panes show only the icons. The arrow keys move the choice, and the group has one Tab stop. The current choice gets the selection fill and an accent bar. Hover gets only a fill. - A Split toggle shows Read beside Write or Source. Each document pane keeps a split flag beside its reading flag. Read ends Split. - Ctrl+Shift+E switches between Read and the editor. Ctrl+E still switches between Write and Source. - "IDE" becomes "Source" in the Chrome type, the tab menu (a View submenu), the status bar, the catalog, the tests, and the docs. - Settings, General, File name title hides the title in Write and Read. It is on by default. - The breadcrumb shows only the folder of the file. The status bar shows the view, not the path. - ModeSwitcher.svelte and its hover test are gone. The new test layout/viewModes covers the control. - The command palette from 5-2 gets its row in docs/menu-surfaces.json. - The user guide Format table is whole again. The 5-2 edit had put the Paragraph and Insert rows under the shortcut table. - 8 new catalog rows and 10 removed rows, in French, Japanese, and Simplified Chinese. - Docs: UI-049, the user guide, ui-design.md, document-tools.md, development.md, and the README feature list. Tests: the new layout/viewModes, new cases in documentPanes.spec.ts and settings.spec.ts, and the chooseView harness helper. 21 smoke tests use the new control. Tests that read the full path from the breadcrumb now read its tooltip.
130 lines
6.5 KiB
JavaScript
130 lines
6.5 KiB
JavaScript
// Tab menus: active and inactive tabs, keyboard focus, pinning, view modes, file actions, ordered closes, cancelled discards, and empty tabs.
|
|
import assert from "node:assert/strict";
|
|
import path from "node:path";
|
|
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
|
|
|
await runSmoke("tabs/menus", async ({ page }) => {
|
|
const output = await outputDir("tabs/menus");
|
|
await mockTauri(page, {
|
|
commands: test => {
|
|
test.prompts = [];
|
|
test.answer = "Cancel";
|
|
Object.defineProperty(navigator, "clipboard", { value: { writeText: async text => { test.clipboard = text; } } });
|
|
return {
|
|
...test.workspace({ root: "C:\\tab-menu-workspace", files: Object.fromEntries(["a.md", "b.md", "c.md", "d.md"].map(name => [name, `# ${name}\n\nOriginal text.\n`])) }),
|
|
workspace_write: () => { throw new Error("Keep unsaved edits for the close test"); },
|
|
workspace_reveal: ({ rel }) => { test.revealed = rel; },
|
|
"plugin:dialog|message": ({ message }) => { test.prompts.push(message); return test.answer; },
|
|
};
|
|
},
|
|
});
|
|
const tab = name => page.getByRole("tab", { name, exact: true });
|
|
const menu = () => page.getByRole("menu", { name: "Tab actions", exact: true });
|
|
const item = name => page.getByRole("menuitem", { name, exact: true });
|
|
const order = () => page.getByRole("tab").evaluateAll(nodes => nodes.map(node => node.dataset.path));
|
|
async function open(name) {
|
|
await page.keyboard.press("Control+p");
|
|
await page.getByRole("textbox", { name: "Find a file" }).fill(name);
|
|
await page.getByRole("dialog").getByRole("button").filter({ hasText: name }).first().click();
|
|
await tab(name).waitFor();
|
|
}
|
|
async function show(name) { await tab(name).click({ button: "right" }); await menu().waitFor(); }
|
|
|
|
await page.goto(smokeUrl);
|
|
await page.getByText("tab-menu-workspace", { exact: true }).waitFor();
|
|
for (const name of ["a.md", "b.md", "c.md", "d.md"]) await open(name);
|
|
await page.locator(".cm-content").filter({ hasText: "Original text." }).waitFor();
|
|
await show("b.md");
|
|
assert.equal(await tab("d.md").getAttribute("aria-selected"), "true");
|
|
assert.equal(await item("Rename…").count(), 0);
|
|
assert.equal(await item("View").count(), 0);
|
|
assert.doesNotMatch(await menu().innerText(), /Alt|Shift|Ctrl/);
|
|
await page.screenshot({ path: path.join(output, "inactive.png") });
|
|
await item("Pin").click();
|
|
assert.equal(await tab("d.md").getAttribute("aria-selected"), "true");
|
|
assert.ok(await tab("b.md").getAttribute("aria-describedby"));
|
|
await show("d.md");
|
|
assert.equal(await item("Close tabs after").isDisabled(), true);
|
|
await page.screenshot({ path: path.join(output, "active.png") });
|
|
await page.keyboard.press("Escape");
|
|
assert.equal(await tab("d.md").evaluate(node => node === document.activeElement), true);
|
|
await tab("d.md").press("Shift+F10");
|
|
assert.equal(await item("Close").evaluate(node => node === document.activeElement), true);
|
|
await page.keyboard.press("End");
|
|
await page.keyboard.press("ArrowRight");
|
|
assert.equal(await item("Move tab left").evaluate(node => node === document.activeElement), true);
|
|
await page.keyboard.press("ArrowLeft");
|
|
await page.keyboard.press("Escape");
|
|
// The View submenu has the same choices as the view control of the pane.
|
|
const view = async name => {
|
|
await show("d.md");
|
|
await item("View").click();
|
|
await page.getByRole(name === "Split" ? "menuitemcheckbox" : "menuitemradio", { name, exact: true }).click();
|
|
};
|
|
await show("d.md");
|
|
await item("View").click();
|
|
assert.equal(await page.getByRole("menuitemradio", { name: "Write", exact: true }).getAttribute("aria-checked"), "true");
|
|
await page.keyboard.press("Escape");
|
|
await page.keyboard.press("Escape");
|
|
await view("Read");
|
|
await page.locator(".md-page").waitFor();
|
|
await view("Split");
|
|
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 page.locator(".md-page").waitFor({ state: "detached" });
|
|
await view("Write");
|
|
await page.locator(".live-writer .cm-editor").waitFor();
|
|
await show("d.md");
|
|
await item("Copy path").click();
|
|
await item("Workspace path").click();
|
|
assert.equal(await page.evaluate(() => window.__TEST__.clipboard), "d.md");
|
|
await show("d.md");
|
|
await item("Show in system explorer").click();
|
|
assert.equal(await page.evaluate(() => window.__TEST__.revealed), "d.md");
|
|
await show("d.md");
|
|
await item("Rename…").click();
|
|
await page.getByRole("dialog").getByRole("textbox").fill("renamed.md");
|
|
await page.getByRole("dialog").getByRole("button", { name: "Continue", exact: true }).click();
|
|
await tab("renamed.md").waitFor();
|
|
await show("a.md");
|
|
await item("Close tabs after").click();
|
|
await tab("renamed.md").waitFor({ state: "detached" });
|
|
assert.deepEqual(await order(), ["a.md", "b.md"]);
|
|
await open("c.md");
|
|
await show("c.md");
|
|
await item("Close others").click();
|
|
await tab("a.md").waitFor({ state: "detached" });
|
|
assert.deepEqual(await order(), ["b.md", "c.md"]);
|
|
await page.locator(".cm-content").click();
|
|
await page.keyboard.press("Control+End");
|
|
await page.keyboard.type("Unsaved text");
|
|
await tab("c.md •").waitFor();
|
|
await show("c.md •");
|
|
await item("Close all").click();
|
|
await page.waitForFunction(() => window.__TEST__.prompts.length === 1);
|
|
assert.deepEqual(await order(), ["b.md", "c.md"]);
|
|
await page.evaluate(() => { window.__TEST__.answer = "Ok"; });
|
|
await show("c.md •");
|
|
await item("Close all").click();
|
|
await tab("c.md •").waitFor({ state: "detached" });
|
|
assert.deepEqual(await order(), ["b.md"]);
|
|
await show("b.md");
|
|
assert.equal(await item("Close all").isDisabled(), true);
|
|
await item("Unpin").click();
|
|
await show("b.md");
|
|
await item("Close").click();
|
|
await tab("b.md").waitFor({ state: "detached" });
|
|
// Closing the last tab leaves an empty tab (src/lib/layout/Workbench.svelte:291), so the plus button adds a second one.
|
|
await tab("New tab").waitFor();
|
|
await page.getByRole("button", { name: "New tab (Ctrl+T)", exact: true }).click();
|
|
const added = page.getByRole("tab", { name: "New tab", exact: true, selected: true });
|
|
await page.waitForFunction(() => document.querySelectorAll('[role="tab"][data-path^="empty:"]').length === 2);
|
|
await added.click({ button: "right" });
|
|
await menu().waitFor();
|
|
assert.equal(await item("Rename…").count(), 0);
|
|
assert.equal(await item("View").count(), 0);
|
|
await page.keyboard.press("Escape");
|
|
}, { timeout: 15000 });
|