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.
137 lines
8.9 KiB
JavaScript
137 lines
8.9 KiB
JavaScript
// Editor menu surfaces: Writer, spelling, IDE, and code menus share the file menu styles; and the code tint match in both themes.
|
|
import assert from "node:assert/strict";
|
|
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
|
|
|
await runSmoke("editor/surfaces", async ({ page }) => {
|
|
await mockTauri(page, {
|
|
commands: test => {
|
|
const note = name => `# ${name}\n\nOriginal text.\n\n\`\`\`js\nconst answer = 42;\n\`\`\`\n\n| Name | Value |\n| --- | --- |\n| Alpha | One |\n`;
|
|
return {
|
|
...test.workspace({
|
|
root: "C:\\tab-menu-workspace",
|
|
files: { ...Object.fromEntries(["a.md", "b.md", "c.md", "d.md"].map(name => [name, note(name)])), "sample.txt": "const answer = 42;\n" },
|
|
folders: ["notes"],
|
|
}),
|
|
spelling_menu_install: () => null,
|
|
spelling_suggestions: ({ word }) => ({ language: "en-US", words: ["Corrected"], misspelled: word === "Original" }),
|
|
};
|
|
},
|
|
});
|
|
const menu = name => page.getByRole('menu', { name, exact: true });
|
|
const item = name => page.getByRole('menuitem', { name, exact: true });
|
|
const output = await outputDir("editor/surfaces");
|
|
const report = [];
|
|
const dismiss = async () => { await page.keyboard.press('Escape'); await page.locator('.rs-menu').waitFor({ state: 'detached' }); };
|
|
const styles = panel => panel.evaluate(node => {
|
|
const row = node.querySelector(':scope > button');
|
|
const a = getComputedStyle(node), b = getComputedStyle(row);
|
|
return [a.backgroundColor, a.borderRadius, a.padding, b.minHeight, b.padding, b.font];
|
|
});
|
|
await page.goto(smokeUrl);
|
|
await page.locator('[data-tree-rel="a.md"]').click();
|
|
await page.locator('.cm-content').waitFor();
|
|
for (const theme of ['dark', 'light']) {
|
|
await page.setViewportSize({ width: 1440, height: 1000 });
|
|
await page.evaluate(async mode => {
|
|
const { saveAppearance } = await import('/src/lib/theme/appearance.ts');
|
|
const canvas = document.createElement('canvas');
|
|
canvas.width = 800; canvas.height = 600;
|
|
const c = canvas.getContext('2d');
|
|
const g = c.createLinearGradient(0, 0, 800, 600);
|
|
g.addColorStop(0, '#628ba8'); g.addColorStop(1, '#b47796');
|
|
c.fillStyle = g; c.fillRect(0, 0, 800, 600);
|
|
saveAppearance({ theme: 'default', mode, newTabBackground: { image: canvas.toDataURL(), overlay: .15, position: 'center', size: 'cover' } });
|
|
}, theme);
|
|
await page.locator('[data-tree-rel="a.md"]').click({ button: 'right' });
|
|
const reference = await styles(menu('File actions'));
|
|
await dismiss();
|
|
const text = page.getByText('Original text.', { exact: true });
|
|
await text.click({ button: 'right', position: { x: 20, y: 8 } });
|
|
const writer = menu('Markdown text actions');
|
|
assert.deepEqual(await styles(writer), reference);
|
|
for (const name of ['Add link', 'Add external link Ctrl+K', 'Format', 'Paragraph', 'Insert', 'Paste Ctrl+V', 'Select all Ctrl+A']) assert.equal(await item(name).count(), 1);
|
|
await item('Corrected').waitFor();
|
|
assert.equal(await item('Spelling').count(), 0, 'Corrections appear directly in the main menu');
|
|
assert.equal(await writer.locator(':scope > button').first().textContent(), 'Corrected');
|
|
await page.screenshot({ path: `${output}/writer-menu-${theme}.png` });
|
|
await item('Corrected').focus(); await page.keyboard.press('Enter');
|
|
await page.getByText('Corrected text.', { exact: true }).waitFor();
|
|
await page.keyboard.press('Control+z');
|
|
await text.waitFor();
|
|
await page.getByRole('button', { name: 'Files', exact: true }).click();
|
|
await page.getByRole('button', { name: 'Hide outline', exact: true }).click();
|
|
await page.setViewportSize({ width: 560, height: 620 });
|
|
await text.click({ button: 'right', position: { x: 20, y: 8 } });
|
|
await item('Corrected').waitFor();
|
|
await page.keyboard.press('Home');
|
|
assert.equal(await item('Corrected').evaluate(node => node === document.activeElement), true);
|
|
const spellingBounds = await writer.boundingBox();
|
|
assert.ok(spellingBounds.x >= 8 && spellingBounds.x + spellingBounds.width <= 552);
|
|
await page.screenshot({ path: `${output}/spelling-narrow-${theme}.png` });
|
|
await page.keyboard.press('Enter');
|
|
await page.getByText('Corrected text.', { exact: true }).waitFor();
|
|
await page.keyboard.press('Control+z');
|
|
await text.waitFor();
|
|
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();
|
|
await page.locator('.cm-content').click({ button: 'right', position: { x: 600, y: 150 } });
|
|
assert.deepEqual(await styles(writer), reference, 'Blank space uses the same actions');
|
|
await item('Format').focus(); await page.keyboard.press('ArrowRight');
|
|
await item('Bold Ctrl+B').click();
|
|
await page.locator('.cm-content').click({ button: 'right', position: { x: 600, y: 150 } });
|
|
await page.getByRole('menuitem', { name: 'Undo Ctrl+Z', exact: true }).click();
|
|
assert.equal(await page.locator('.cm-content').textContent().then(s => s.includes('**')), false, 'Undo reverses the menu edit');
|
|
const tint = await page.locator('.writer-code-line').first().evaluate(node => getComputedStyle(node).backgroundColor);
|
|
assert.ok(tint.includes('/ 0.82') || /rgba\(.+, 0\.82\)/.test(tint), `Writer code tint: ${tint}`);
|
|
await page.screenshot({ path: `${output}/writer-code-${theme}.png` });
|
|
await page.getByRole('group', { name: 'Document view', exact: true }).hover();
|
|
await page.getByRole('button', { name: 'Read', exact: true }).click();
|
|
const readingTint = await page.locator('pre.md-code').evaluate(node => getComputedStyle(node).backgroundColor);
|
|
assert.equal(readingTint, tint, 'Reader and Writer use the same code tint');
|
|
await page.screenshot({ path: `${output}/reader-code-${theme}.png` });
|
|
await page.getByRole('button', { name: 'Edit', exact: true }).click();
|
|
await page.getByRole('group', { name: 'Editor layout', exact: true }).hover();
|
|
await page.getByRole('button', { name: 'IDE', exact: true }).click();
|
|
await page.locator('.source-editor .cm-content').waitFor();
|
|
await page.locator('.source-editor').click({ button: 'right', position: { x: 500, y: 400 } });
|
|
assert.deepEqual(await styles(writer), reference, 'Markdown IDE retains the same menu');
|
|
await dismiss();
|
|
await page.locator('[data-tree-rel="sample.txt"]').click();
|
|
await page.locator('.source-editor').click({ button: 'right', position: { x: 500, y: 400 } });
|
|
const code = menu('Code text actions');
|
|
assert.deepEqual(await styles(code), reference, 'Code IDE uses the host menu');
|
|
// The host menu is the only menu. The editor adds no menu of its own.
|
|
assert.equal(await page.getByRole('menu').count(), 1);
|
|
assert.equal(await code.getByRole('menuitem', { name: 'Command palette F1', exact: true }).count(), 0);
|
|
await page.screenshot({ path: `${output}/ide-menu-${theme}.png` });
|
|
await dismiss();
|
|
await page.getByRole('button', { name: 'Files', exact: true }).click();
|
|
await page.getByRole('button', { name: 'Hide outline', exact: true }).click();
|
|
await page.setViewportSize({ width: 560, height: 620 });
|
|
await page.locator('.source-editor').click({ button: 'right', position: { x: 100, y: 300 } });
|
|
await code.waitFor();
|
|
const bounds = await code.boundingBox();
|
|
assert.ok(bounds.x >= 0 && bounds.x + bounds.width <= 560);
|
|
await page.keyboard.press('End');
|
|
assert.equal(await page.getByRole('menuitem', { name: 'Select all Ctrl+A', exact: true }).evaluate(n => n === document.activeElement), true);
|
|
await page.screenshot({ path: `${output}/ide-narrow-${theme}.png` });
|
|
await page.keyboard.press('Enter');
|
|
await code.waitFor({ state: 'detached' });
|
|
// The keyboard choice runs the action: the selection covers the whole file.
|
|
assert.equal(await page.evaluate(async () => {
|
|
const { EditorView } = await import('/node_modules/@codemirror/view/dist/index.js');
|
|
const view = EditorView.findFromDOM(document.querySelector('.source-editor .cm-content'));
|
|
return view.state.selection.main.from === 0 && view.state.selection.main.to === view.state.doc.length;
|
|
}), true);
|
|
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();
|
|
await page.locator('[data-tree-rel="a.md"]').click();
|
|
await page.getByRole('group', { name: 'Editor layout', exact: true }).hover();
|
|
await page.getByRole('button', { name: 'Writer', exact: true }).click();
|
|
report.push({ theme, passed: ['word and blank menu parity', 'spelling correction and undo', 'Writer/IDE parity', 'undo menu action', 'code menu host styles', 'transparent code in Writer/Reader', 'narrow keyboard menu'], nativeDesktop: 'not tested' });
|
|
}
|
|
console.log(JSON.stringify(report, null, 2));
|
|
}, { timeout: 15000 });
|