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.
106 lines
5.8 KiB
JavaScript
106 lines
5.8 KiB
JavaScript
// Note templates and task lines: template creation, filename focus, task entry, checkbox toggles, lone hyphens, and Setext headings.
|
|
import assert from "node:assert/strict";
|
|
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
|
|
|
await runSmoke("editor/templatesAndTasks", async ({ page }) => {
|
|
await mockTauri(page, {
|
|
commands: test => {
|
|
const workspace = test.workspace({
|
|
root: "C:\\smoke-workspace",
|
|
files: {
|
|
"notes/welcome.md": "---\ntitle: Welcome\n---\n\n# Working notes\n\nFirst paragraph.\n\n- [ ] A task\n\n[[second]]\n",
|
|
"notes/second.md": "# Second note\n",
|
|
"src/hello.py": "print('hello')\n",
|
|
},
|
|
writeEvents: true,
|
|
});
|
|
test.files = workspace.files;
|
|
return {
|
|
...workspace,
|
|
// Saves send the last saved text. Reject a save when the file changed, as the backend does.
|
|
workspace_write: args => {
|
|
if (args.expected !== undefined && workspace.files.get(args.rel) !== args.expected) throw new Error("Save blocked: file changed on disk");
|
|
return workspace.workspace_write(args);
|
|
},
|
|
// The tree hides the root .runestone folder; its templates folder stays listable.
|
|
workspace_list: args => workspace.workspace_list(args).filter(entry => args.rel || entry.rel_path !== ".runestone"),
|
|
};
|
|
},
|
|
});
|
|
const output = await outputDir("editor/templatesAndTasks");
|
|
await page.goto(smokeUrl);
|
|
await page.getByText('smoke-workspace', { exact: true }).waitFor();
|
|
// Save the empty task lines from the reported template, then create through
|
|
// the normal note action so the filename receives the initial focus.
|
|
await page.evaluate(async () => {
|
|
const { saveNoteTemplate } = await import('/src/lib/workspace/templates.ts');
|
|
await saveNoteTemplate('To Do', '- [ ] \n'.repeat(10));
|
|
});
|
|
await page.getByRole('button', { name: 'New tab (Ctrl+T)', exact: true }).click();
|
|
await page.getByRole('button', { name: 'New note', exact: true }).last().click();
|
|
await page.getByRole('menuitem', { name: 'To Do', exact: true }).click();
|
|
const title = page.getByRole('textbox', { name: 'Note filename', exact: true });
|
|
await title.waitFor();
|
|
await page.waitForFunction(() => document.activeElement?.getAttribute('aria-label') === 'Note filename');
|
|
await page.evaluate(async () => {
|
|
const { EditorView } = await import('/node_modules/@codemirror/view/dist/index.js');
|
|
window.__CM__ = EditorView.findFromDOM(document.querySelector('.cm-content'));
|
|
});
|
|
const count = () => page.locator('.writer-checkbox').count();
|
|
const expectCount = async expected => {
|
|
await page.waitForFunction(expected => document.querySelectorAll('.writer-checkbox').length === expected, expected);
|
|
assert.equal(await count(), expected);
|
|
};
|
|
const setSource = source => page.evaluate(source => {
|
|
window.__CM__.dispatch({ changes: { from: 0, to: window.__CM__.state.doc.length, insert: source }, selection: { anchor: source.length } });
|
|
window.__CM__.focus();
|
|
}, source);
|
|
const plain = 'Some generic mobs or factions,\n-';
|
|
for (const mode of ['dark', 'light']) {
|
|
await page.evaluate(async mode => (await import('/src/lib/theme/appearance.ts')).saveAppearance({ theme: 'default', mode }), mode);
|
|
for (const width of [1440, 600]) {
|
|
await page.setViewportSize({ width, height: width === 600 ? 760 : 1000 });
|
|
if (width === 600) {
|
|
await page.getByRole('button', { name: 'Files', exact: true }).click();
|
|
await page.getByRole('button', { name: 'Hide outline', exact: true }).click();
|
|
}
|
|
if (!(await title.isVisible())) await page.getByRole('button', { name: 'Rename note', exact: true }).click();
|
|
await title.focus();
|
|
await expectCount(10);
|
|
await page.screenshot({ path: `${output}/${mode}-${width}-template-title.png` });
|
|
await page.keyboard.press('Escape');
|
|
await page.evaluate(() => {
|
|
const view = window.__CM__;
|
|
view.dispatch({ selection: { anchor: 0 } }); view.focus();
|
|
});
|
|
await expectCount(9);
|
|
await page.keyboard.press('End');
|
|
await page.keyboard.type('First task');
|
|
await expectCount(10);
|
|
await page.locator('.writer-checkbox').first().click();
|
|
assert.match(await page.evaluate(() => window.__CM__.state.sliceDoc()), /^- \[x\] First task/);
|
|
await page.screenshot({ path: `${output}/${mode}-${width}-template-edit.png` });
|
|
|
|
await setSource(plain);
|
|
assert.equal(await page.locator('.writer-h2').count(), 0, 'A lone hyphen must not enlarge preceding prose');
|
|
await page.screenshot({ path: `${output}/${mode}-${width}-single-hyphen.png` });
|
|
await page.keyboard.type(' Item');
|
|
assert.equal(await page.locator('.writer-h2').count(), 0, 'The hyphen continues into a list');
|
|
assert.equal(await page.evaluate(() => window.__CM__.state.sliceDoc()), plain + ' Item');
|
|
await setSource(plain + '-');
|
|
assert.equal(await page.locator('.writer-h2').count(), 1, 'Two hyphens retain Setext heading support');
|
|
await setSource('A normal heading\n===\n');
|
|
assert.equal(await page.locator('.writer-h1').count(), 1);
|
|
// Restore the template for the next theme and size without an active body caret.
|
|
await setSource('- [ ] \n'.repeat(10));
|
|
await page.getByRole('button', { name: 'Rename note', exact: true }).click();
|
|
if (width === 600) {
|
|
await page.setViewportSize({ width: 1440, height: 1000 });
|
|
await page.getByRole('button', { name: 'Files', exact: true }).click();
|
|
await page.getByRole('button', { name: 'Show outline', exact: true }).click();
|
|
}
|
|
}
|
|
}
|
|
console.log('PASS: template creation, filename focus, keyboard task entry, checkbox toggle, lone hyphen, list continuation, and Setext headings in both themes and narrow layouts.');
|
|
});
|