Files
RuneStone/tests/smoke/tabs/order.smoke.mjs
T
Knotty Wyvern ebacdb8164 Add the command palette, Write formatting keys, and platform labels
Phase 5-2.

- Ctrl+Shift+P opens the command palette: every workbench command with
  its shortcut, then the plugin commands (UI-048).
- In Write, Ctrl+B, Ctrl+I, Ctrl+Shift+X, and Ctrl+Shift+H format the
  selection, and Ctrl+K inserts a Markdown link. The Format menu shows
  these shortcuts.
- Ctrl+\ toggles the side pane. It matches the physical key on every
  keyboard layout. Ctrl+B now belongs to Write.
- Help lists every shortcut in groups, open by default. The list comes
  from the command table.
- src/lib/ui/shortcuts.ts writes shortcut labels for the platform:
  Ctrl+Shift+P on Windows and Linux, and the macOS symbols on a Mac.
  The catalog uses placeholders, so no translation contains "Ctrl".
- 19 new catalog rows, and 10 rows converted to placeholders, in
  French, Japanese, and Simplified Chinese.
- Docs: UI-048, the user guide keyboard tables, and a label rule in
  ui-design.md.

New tests: layout/commands, tests/unit/ui/shortcuts.spec.ts, and new
cases in workbenchKeys.spec.ts. Tests that read the old labels or
pressed Ctrl+B for the side pane now use the new names and Ctrl+\.

The smoke harness raises the resource timing buffer to 5000 entries.
The new modules pushed the CodeMirror language module past the
default 250 entries, so editor/markdownPaste could not find its URL.
2026-10-28 19:10:25 -07:00

106 lines
6.0 KiB
JavaScript

// Tab order: pointer drags, cancellation, keyboard moves, tab menus, empty tabs, and an overflowing tab bar.
import assert from "node:assert/strict";
import { mockTauri, runSmoke, settle as settleFrames, smokeUrl } from "../_harness/index.mjs";
await runSmoke("tabs/order", async ({ page }) => {
await mockTauri(page, {
commands: test => {
const files = new Map(Array.from({ length: 16 }, (_, i) => [`note-${String(i).padStart(2, "0")}.md`, `# Note ${i}\n\nKeep this text.\n`]));
files.set("note-00.md", Array.from({ length: 200 }, (_, i) => `Paragraph ${i}.\n\n`).join(""));
return {
...test.workspace({ root: "C:\\tab-order-workspace", files }),
workspace_search: () => [],
"plugin:dialog|message": () => "Cancel",
};
},
});
const settle = () => settleFrames(page);
const tab = name => page.getByRole("tab", { name, exact: true });
const order = () => page.getByRole("tablist", { name: "Working tabs" }).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 drag(from, to, side, cancel) {
const source = await tab(from).boundingBox();
const target = await tab(to).boundingBox();
await page.mouse.move(source.x + source.width / 2, source.y + source.height / 2);
await page.mouse.down();
await page.mouse.move(side === "before" ? target.x + 2 : target.x + target.width - 2, target.y + target.height / 2, { steps: 10 });
if (cancel === "escape") await page.keyboard.press("Escape");
if (cancel === "outside") await page.mouse.move(target.x, target.y + 100);
await page.mouse.up();
await settle();
}
await page.goto(smokeUrl);
await page.getByText("tab-order-workspace", { exact: true }).waitFor();
for (const name of ["note-00.md", "note-01.md", "note-02.md"]) await open(name);
await drag("note-00.md", "note-02.md", "after");
assert.deepEqual(await order(), ["note-01.md", "note-02.md", "note-00.md"]);
assert.equal(await tab("note-02.md").getAttribute("aria-selected"), "true");
await drag("note-00.md", "note-01.md", "before");
assert.deepEqual(await order(), ["note-00.md", "note-01.md", "note-02.md"]);
for (const cancel of ["escape", "outside"]) {
await drag("note-00.md", "note-02.md", "after", cancel);
assert.deepEqual(await order(), ["note-00.md", "note-01.md", "note-02.md"]);
}
await tab("note-00.md").click();
assert.equal(await tab("note-00.md").getAttribute("aria-selected"), "true");
await page.locator(".cm-scroller").evaluate(node => { node.scrollTop = 1200; });
await settle();
const scrollTop = await page.locator(".cm-scroller").evaluate(node => node.scrollTop);
assert.ok(scrollTop > 1000);
await tab("note-00.md").press("Alt+Shift+ArrowRight");
await settle();
assert.deepEqual(await order(), ["note-01.md", "note-00.md", "note-02.md"]);
assert.ok(Math.abs(await page.locator(".cm-scroller").evaluate(node => node.scrollTop) - scrollTop) < 5);
assert.equal(await tab("note-00.md").evaluate(node => document.activeElement === node), true);
await tab("note-00.md").press("ArrowRight");
assert.equal(await tab("note-02.md").getAttribute("aria-selected"), "true");
await tab("note-02.md").press("Shift+F10");
await page.getByRole("menuitem", { name: "Move tab", exact: true }).click();
assert.equal(await page.getByRole("menuitem", { name: /Move tab right/ }).isDisabled(), true);
await page.getByRole("menuitem", { name: /Move tab left/ }).click();
assert.deepEqual(await order(), ["note-01.md", "note-02.md", "note-00.md"]);
await tab("note-01.md").click({ button: "right" });
await page.getByRole("menuitem", { name: "Move tab", exact: true }).click();
assert.equal(await page.getByRole("menuitem", { name: /Move tab left/ }).isDisabled(), true);
await page.keyboard.press("Escape");
assert.equal(await page.getByRole("menu", { name: "Tab actions" }).count(), 0);
console.log("PASS: pointer moves, cancellation, keyboard moves, and tab menus");
await page.getByRole("button", { name: "New tab (Ctrl+T)", exact: true }).click();
await tab("New tab").press("Alt+Shift+Home");
assert.match((await order())[0], /^empty:/);
await page.getByRole("button", { name: "Close New tab", exact: true }).click();
await tab("note-01.md").click({ button: "middle" });
assert.deepEqual(await order(), ["note-02.md", "note-00.md"]);
console.log("PASS: empty tabs and middle-click close after reorder");
for (let i = 3; i < 16; i++) await open(`note-${String(i).padStart(2, "0")}.md`);
const bar = page.getByRole("tablist", { name: "Working tabs" });
assert.ok(await bar.evaluate(node => node.scrollLeft > 0));
await tab("note-15.md").press("Alt+Shift+Home");
assert.equal((await order())[0], "note-15.md");
assert.equal(await bar.evaluate(node => node.scrollLeft), 0);
const source = await tab("note-15.md").boundingBox();
const bounds = await bar.boundingBox();
await page.mouse.move(source.x + source.width / 2, source.y + source.height / 2);
await page.mouse.down();
await page.mouse.move(bounds.x + bounds.width - 3, source.y + source.height / 2, { steps: 10 });
await page.waitForFunction(() => {
const bar = document.querySelector('[aria-label="Working tabs"]');
return bar.scrollLeft >= bar.scrollWidth - bar.clientWidth - 2;
});
// Native drag needs a fresh pointer event after the strip scrolls beneath it.
await page.mouse.move(bounds.x + bounds.width - 4, source.y + source.height / 2);
await page.mouse.move(bounds.x + bounds.width - 3, source.y + source.height / 2);
await page.mouse.up();
await settle();
assert.equal((await order()).at(-1), "note-15.md");
console.log("PASS: automatic scrolling and drag to the end of an overflowing tab bar");
if (process.env.SCREENSHOT_PATH) await page.screenshot({ path: process.env.SCREENSHOT_PATH });
});