// The command palette (Ctrl+Shift+P), the side pane on Ctrl+\, the generated shortcut list in Help, and the Write formatting shortcuts. import assert from "node:assert/strict"; import path from "node:path"; import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs"; const name = "layout/commands"; await runSmoke(name, async ({ page }) => { const output = await outputDir(name); await mockTauri(page, { commands: test => { const workspace = test.workspace({ root: "C:\\commands", files: { "a.md": "# Note\n\nalpha beta gamma delta epsilon\n" } }); test.files = workspace.files; return { ...workspace, plugins_snapshot: () => ({ root: "C:/plugins", plugins: [] }), spelling_menu_install: () => null }; }, }); await page.goto(smokeUrl); await page.locator('[data-tree-rel="a.md"]').click(); await page.locator(".live-writer .cm-content").waitFor(); // The palette lists the app commands with their shortcuts and runs the chosen one. await page.keyboard.press("Control+Shift+P"); const palette = page.getByRole("dialog", { name: "Commands", exact: true }); await palette.waitFor(); assert.equal(await palette.getByRole("button", { name: "Save the active file Ctrl+S", exact: true }).count(), 1); assert.match(await palette.locator("footer").textContent(), /\d+ commands/); await page.screenshot({ path: path.join(output, "palette.png") }); await page.getByRole("textbox", { name: "Find a command", exact: true }).fill("side pane"); assert.deepEqual((await palette.locator(".rs-picker-row").allTextContents()).map(text => text.replace(/\s+/g, " ").trim()), ["Show or hide the side pane Ctrl+\\"]); assert.equal(await page.locator("aside.left").count(), 1); await page.keyboard.press("Enter"); await palette.waitFor({ state: "detached" }); await page.locator("aside.left").waitFor({ state: "detached" }); // Ctrl+\ shows the side pane again. Ctrl+B no longer toggles it. await page.keyboard.press("Control+Backslash"); await page.locator("aside.left").waitFor(); // Write formatting shortcuts make the same edits as the Format menu. const select = word => page.evaluate(async word => { const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js"); const view = EditorView.findFromDOM(document.querySelector(".live-writer .cm-content")); const from = view.state.doc.toString().indexOf(word); view.dispatch({ selection: { anchor: from, head: from + word.length } }); view.focus(); }, word); for (const [word, keys] of [["beta", "Control+b"], ["gamma", "Control+i"], ["delta", "Control+Shift+X"], ["epsilon", "Control+Shift+H"], ["alpha", "Control+k"]]) { await select(word); await page.keyboard.press(keys); } assert.equal(await page.locator("aside.left").count(), 1, "Ctrl+B in Write does not hide the side pane"); await page.keyboard.press("Control+s"); await page.waitForFunction(() => window.__TEST__.files.get("a.md").includes("==epsilon==")); assert.equal(await page.evaluate(() => window.__TEST__.files.get("a.md")), "# Note\n\n[alpha]() **beta** *gamma* ~~delta~~ ==epsilon==\n"); // The Format menu shows the shortcuts. await page.locator(".live-writer .cm-line").filter({ hasText: "beta" }).click({ button: "right" }); await page.getByRole("menuitem", { name: "Format", exact: true }).hover(); for (const label of ["Bold Ctrl+B", "Italic Ctrl+I", "Strikethrough Ctrl+Shift+X", "Highlight Ctrl+Shift+H"]) await page.getByRole("menuitem", { name: label, exact: true }).waitFor(); assert.equal(await page.getByRole("menuitem", { name: "Add external link Ctrl+K", exact: true }).count(), 1); await page.keyboard.press("Escape"); await page.keyboard.press("Escape"); // Help lists every shortcut, open, in groups. await page.keyboard.press("F1"); const help = page.getByRole("dialog", { name: "Help and about", exact: true }); await help.waitFor(); const list = help.locator("details").filter({ hasText: "Keyboard shortcuts" }); assert.equal(await list.getAttribute("open"), ""); for (const heading of ["General", "Write", "Files"]) await list.getByRole("heading", { name: heading, exact: true }).waitFor(); const rows = await list.locator("dl div").allTextContents(); for (const row of ["Show all commandsCtrl+Shift+P", "Show or hide the side paneCtrl+\\", "BoldCtrl+B", "Delete permanentlyShift+Delete", "Help and aboutF1"]) assert(rows.includes(row), `Help lists ${row}`); await page.screenshot({ path: path.join(output, "help-shortcuts.png") }); console.log("PASS: the command palette, Ctrl+\\ for the side pane, Write formatting shortcuts, menu shortcut labels, and the Help shortcut list"); });