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.
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
// 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");
|
||||
});
|
||||
@@ -69,7 +69,7 @@ await runSmoke("layout/outline", async ({ browser }) => {
|
||||
await page.getByRole("button", { name: "Hide outline", exact: true }).click();
|
||||
await reopen();
|
||||
assert.equal(await page.locator(".left, .right").count(), 0);
|
||||
await page.keyboard.press("Control+b");
|
||||
await page.keyboard.press("Control+Backslash");
|
||||
assert.equal(await page.getByRole("button", { name: "Bookmarks", exact: true }).getAttribute("aria-pressed"), "true");
|
||||
await page.getByRole("button", { name: "Show outline", exact: true }).click();
|
||||
assert.deepEqual(await widths(), resized);
|
||||
|
||||
Reference in New Issue
Block a user