Phase 5-3. - One radio group shows Write, Source, and Read at all times, with an icon and a name. Narrow panes show only the icons. The arrow keys move the choice, and the group has one Tab stop. The current choice gets the selection fill and an accent bar. Hover gets only a fill. - A Split toggle shows Read beside Write or Source. Each document pane keeps a split flag beside its reading flag. Read ends Split. - Ctrl+Shift+E switches between Read and the editor. Ctrl+E still switches between Write and Source. - "IDE" becomes "Source" in the Chrome type, the tab menu (a View submenu), the status bar, the catalog, the tests, and the docs. - Settings, General, File name title hides the title in Write and Read. It is on by default. - The breadcrumb shows only the folder of the file. The status bar shows the view, not the path. - ModeSwitcher.svelte and its hover test are gone. The new test layout/viewModes covers the control. - The command palette from 5-2 gets its row in docs/menu-surfaces.json. - The user guide Format table is whole again. The 5-2 edit had put the Paragraph and Insert rows under the shortcut table. - 8 new catalog rows and 10 removed rows, in French, Japanese, and Simplified Chinese. - Docs: UI-049, the user guide, ui-design.md, document-tools.md, development.md, and the README feature list. Tests: the new layout/viewModes, new cases in documentPanes.spec.ts and settings.spec.ts, and the chooseView harness helper. 21 smoke tests use the new control. Tests that read the full path from the breadcrumb now read its tooltip.
126 lines
5.9 KiB
JavaScript
126 lines
5.9 KiB
JavaScript
// Undo history survives tab switches, window focus, Source edits, and table cell edits.
|
|
import assert from "node:assert/strict";
|
|
import { mockTauri, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
|
|
|
await runSmoke("editor/undoHistory", 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);
|
|
},
|
|
};
|
|
},
|
|
});
|
|
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();
|
|
}
|
|
async function writer() {
|
|
await page.locator('.cm-content').waitFor();
|
|
return page.evaluate(async () => {
|
|
const { EditorView } = await import('/node_modules/@codemirror/view/dist/index.js');
|
|
window.__WRITER__ = EditorView.findFromDOM(document.querySelector('.cm-content'));
|
|
return window.__WRITER__.state.sliceDoc();
|
|
});
|
|
}
|
|
async function expectWriter(expected) {
|
|
await writer();
|
|
try { await page.waitForFunction(text => window.__WRITER__.state.sliceDoc() === text, expected); } catch (error) { console.log({ expected, actual: await writer(), errors: page.errors }); throw error; }
|
|
}
|
|
await page.goto(smokeUrl);
|
|
await page.getByText('smoke-workspace', { exact: true }).waitFor();
|
|
await open('welcome.md');
|
|
const original = await writer();
|
|
await page.locator('.cm-content').click();
|
|
await page.keyboard.press('Control+End');
|
|
await page.keyboard.type(' first edit');
|
|
await expectWriter(original + ' first edit');
|
|
await page.keyboard.press('Control+s');
|
|
await open('second.md');
|
|
await writer();
|
|
await page.getByRole('tab', { name: 'welcome.md', exact: true }).click();
|
|
await expectWriter(original + ' first edit');
|
|
await page.keyboard.press('Control+z');
|
|
await expectWriter(original);
|
|
await page.keyboard.press('Control+y');
|
|
await expectWriter(original + ' first edit');
|
|
console.log('PASS: saved Writer edit survives tab switch with undo and redo');
|
|
await page.evaluate(() => window.dispatchEvent(new Event('focus')));
|
|
await page.keyboard.press('Control+z');
|
|
await expectWriter(original);
|
|
await page.keyboard.press('Control+y');
|
|
await expectWriter(original + ' first edit');
|
|
assert.equal(await page.evaluate(() => window.__WRITER__.state.selection.main.head), (original + ' first edit').length);
|
|
console.log('PASS: Writer undo and redo survive window focus refresh and restore the caret');
|
|
await page.keyboard.press('Control+e');
|
|
await page.locator('.source-editor .cm-content').waitFor();
|
|
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'));
|
|
view.dispatch({ selection: { anchor: view.state.doc.length } });
|
|
view.focus();
|
|
window.__IDE__ = view;
|
|
});
|
|
await page.keyboard.type(' second edit');
|
|
assert.equal(await page.evaluate(() => window.__IDE__.dom.isConnected), true, 'Typing keeps the same Source editor mounted');
|
|
assert.equal(await page.evaluate(() => window.__IDE__.state.doc.toString()), original + ' first edit second edit');
|
|
await page.keyboard.press('Control+e');
|
|
await expectWriter(original + ' first edit second edit');
|
|
await page.locator('.cm-content').click();
|
|
// One burst of typing is one undo step, in Source as in Write.
|
|
await page.keyboard.press('Control+z');
|
|
await expectWriter(original + ' first edit');
|
|
await page.keyboard.press('Control+z');
|
|
await expectWriter(original);
|
|
await page.keyboard.press('Control+y');
|
|
await expectWriter(original + ' first edit');
|
|
await page.keyboard.press('Control+y');
|
|
await expectWriter(original + ' first edit second edit');
|
|
console.log('PASS: Writer undo includes edits from Source mode');
|
|
const tableSource = '# Table\n\n| A | B |\n| --- | --- |\n| One | Two |\n\nTail.\n';
|
|
await page.evaluate(source => {
|
|
window.__TEST__.files.set('table.md', source);
|
|
window.__TEST__.emit('workspace-event', { root: window.__TEST__.root, kind: 'create', paths: ['table.md'] });
|
|
}, tableSource);
|
|
await open('table.md');
|
|
await writer();
|
|
const cells = page.locator('.writer-table tbody td');
|
|
await cells.nth(0).click();
|
|
await page.keyboard.press('Control+a');
|
|
await page.keyboard.type('Alpha');
|
|
await cells.nth(1).click();
|
|
await page.keyboard.press('Control+a');
|
|
await page.keyboard.type('Beta');
|
|
await page.keyboard.press('Escape');
|
|
const editedTable = await writer();
|
|
assert.ok(editedTable.includes('Alpha') && editedTable.includes('Beta'));
|
|
await page.getByRole('tab', { name: 'welcome.md', exact: true }).click();
|
|
await writer();
|
|
await page.getByRole('tab', { name: 'table.md', exact: true }).click();
|
|
await writer();
|
|
await page.keyboard.press('Control+z');
|
|
await expectWriter(editedTable.replace('Beta', 'Two'));
|
|
await page.keyboard.press('Control+z');
|
|
await expectWriter(tableSource);
|
|
await page.keyboard.press('Control+y');
|
|
await expectWriter(editedTable.replace('Beta', 'Two'));
|
|
await page.keyboard.press('Control+y');
|
|
await expectWriter(editedTable);
|
|
console.log('PASS: table cell typing stays grouped per cell across tab switches');
|
|
});
|