Phase 4b. DocumentEditor.svelte replaces LiveWriter.svelte and the Monaco EditorHost.svelte. Each open document has one CodeMirror state. Write and Source are two compartment configurations of it, so they share the undo history. editorStates.ts keeps the state while the tab stays open. The Monaco model, the diff bridge, its timers, and sessions.ts are gone. - Source: syntax colors from the theme tokens, lazy language packages, line numbers, folding, and the current line in IDE, wrapped lines in Writing, several carets, and bracket matching and closing. - Lists (card 088e778b): Tab nests a list item and Shift+Tab moves it up, in Write and Source. Both renumber the list. The source keeps "1.". Write and Read show numbers, letters, then Roman numerals. - Indent (card 696c30ce): a fixed 4 spaces in Write and Source. - The code menu uses CodeMirror commands. The command palette item and the Monaco styles, search, theme, and workers are removed. - @codemirror/legacy-modes is pinned to 6.5.4. Version 6.5.5 uses parser types that do not match @codemirror/language 6.12. - 26 smoke tests use CodeMirror instead of Monaco. New tests: editor/listNesting and the markdownLists unit tests. - Docs: development, UI design, plugin host, user guide, and UI-040. pnpm check, pnpm test (341 of 341), and pnpm build pass. The full smoke suite passes, except one template test that passed on retry.
151 lines
8.7 KiB
JavaScript
151 lines
8.7 KiB
JavaScript
// One full-width document Find in Writer, table cells, IDE source, and Reading: replacement, regex, CRLF, focus return, both themes, and narrow controls.
|
|
import assert from "node:assert/strict";
|
|
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
|
|
|
await runSmoke("find/documentFind", async ({ page }) => {
|
|
const output = await outputDir("find/documentFind");
|
|
await mockTauri(page, {
|
|
commands: test => {
|
|
const workspace = test.workspace({
|
|
root: "C:\\smoke-workspace",
|
|
writeEvents: true,
|
|
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",
|
|
},
|
|
});
|
|
return {
|
|
...workspace,
|
|
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);
|
|
},
|
|
workspace_search: () => [],
|
|
"plugin:dialog|message": () => "Cancel",
|
|
};
|
|
},
|
|
});
|
|
|
|
const sample = "# Alpha\n\nAlpha alpha alphabet\n\n| Name | Value |\n| --- | --- |\n| Alpha | One |\n| Beta | Two |\n\nLast Alpha paragraph.\n";
|
|
const find = page.getByRole("textbox", { name: "Find in document", exact: true });
|
|
const replace = page.getByRole("textbox", { name: "Replace with", exact: true });
|
|
async function mode(group, value) {
|
|
await page.getByRole("group", { name: group, exact: true }).hover();
|
|
await page.getByRole("button", { name: value, exact: true }).click();
|
|
}
|
|
async function onePanel() {
|
|
assert.equal(await page.locator('.rs-find-bar:visible').count(), 1);
|
|
assert.equal(await page.locator('.cm-search').count(), 0, 'No default CodeMirror search panel');
|
|
const bar = await page.locator('.rs-find-bar:visible').boundingBox();
|
|
const pane = await page.locator('.editor.pane-active').boundingBox();
|
|
assert.ok(Math.abs(bar.width - pane.width) < 3, 'Find spans the document pane');
|
|
}
|
|
async function sourceEditor() {
|
|
await page.waitForFunction(() => !!document.querySelector('.source-editor .cm-content'));
|
|
return page.evaluate(async () => {
|
|
const { EditorView } = await import('/node_modules/@codemirror/view/dist/index.js');
|
|
window.__SOURCE__ = EditorView.findFromDOM(document.querySelector('.source-editor .cm-content'));
|
|
window.__SOURCE__.focus();
|
|
});
|
|
}
|
|
await page.goto(smokeUrl);
|
|
await page.getByText("smoke-workspace", { exact: true }).waitFor();
|
|
await page.keyboard.press("Control+p");
|
|
await page.getByRole("textbox", { name: "Find a file" }).fill("welcome.md");
|
|
await page.getByRole("dialog").getByRole("button").filter({ hasText: "welcome.md" }).first().click();
|
|
for (const theme of ['dark', 'light']) {
|
|
await page.evaluate(async theme => {
|
|
const { saveAppearance } = await import('/src/lib/theme/appearance.ts');
|
|
saveAppearance({ theme: 'default', mode: theme });
|
|
}, theme);
|
|
await page.getByRole('textbox', { name: 'Writing editor', exact: true }).waitFor();
|
|
await page.evaluate(async sample => {
|
|
const { EditorView } = await import('/node_modules/@codemirror/view/dist/index.js');
|
|
window.__CM__ = EditorView.findFromDOM(document.querySelector('.live-writer > .cm-editor .cm-content'));
|
|
window.__CM__.dispatch({ changes: { from: 0, to: window.__CM__.state.doc.length, insert: sample }, selection: { anchor: 0 } });
|
|
window.__CM__.focus();
|
|
}, sample);
|
|
await page.keyboard.press('Control+f');
|
|
await find.fill('Alpha');
|
|
await onePanel();
|
|
await page.screenshot({ path: `${output}/writer-${theme}.png` });
|
|
await page.keyboard.press('Escape');
|
|
await page.locator('.live-writer td').first().dblclick();
|
|
await page.locator('.writer-cell-editor').waitFor();
|
|
await page.keyboard.press('Control+f');
|
|
await onePanel();
|
|
assert.equal(await find.evaluate(node => node === document.activeElement), true, 'Table focus opens the document find');
|
|
assert.equal(await page.locator('.writer-cell-editor .rs-find-bar').count(), 0);
|
|
await find.fill('Last Alpha');
|
|
await page.keyboard.press('Enter');
|
|
assert.match(await page.evaluate(() => window.__CM__.state.sliceDoc(window.__CM__.state.selection.main.from, window.__CM__.state.selection.main.to)), /Last Alpha/);
|
|
await page.screenshot({ path: `${output}/table-focus-${theme}.png` });
|
|
await page.keyboard.press('Escape');
|
|
await mode('Editor layout', 'IDE');
|
|
await sourceEditor();
|
|
await page.evaluate(() => { const view = window.__SOURCE__; view.dispatch({ changes: { from: 0, to: view.state.doc.length, insert: 'Alpha alpha alphabet\r\nAlpha second\r\nAlpha third' }, selection: { anchor: 0 } }); });
|
|
await page.keyboard.press('Control+f');
|
|
await find.fill('Alpha');
|
|
await onePanel();
|
|
await page.keyboard.press('Enter');
|
|
const selection = () => page.evaluate(() => JSON.stringify(window.__SOURCE__.state.selection.main));
|
|
const first = await selection();
|
|
await page.keyboard.press('Enter');
|
|
assert.notEqual(await selection(), first);
|
|
await page.keyboard.press('Shift+Enter');
|
|
assert.equal(await selection(), first);
|
|
await page.getByRole('checkbox', { name: 'Match case' }).check();
|
|
await page.getByRole('checkbox', { name: 'Whole word' }).check();
|
|
await replace.fill('Gamma');
|
|
await page.getByRole('button', { name: 'Replace all', exact: true }).click();
|
|
assert.equal(await page.evaluate(() => window.__SOURCE__.state.doc.toString()), 'Gamma alpha alphabet\nGamma second\nGamma third');
|
|
await page.getByRole('checkbox', { name: 'Regex' }).check();
|
|
await find.fill('[');
|
|
assert.equal(await find.getAttribute('aria-invalid'), 'true');
|
|
assert.equal(await page.getByRole('button', { name: 'Replace all', exact: true }).isDisabled(), true);
|
|
await find.fill('(?<=G)(amma)');
|
|
await page.getByRole('checkbox', { name: 'Whole word' }).uncheck();
|
|
await replace.fill('$1!');
|
|
await page.getByRole('button', { name: 'Replace all', exact: true }).click();
|
|
assert.match(await page.evaluate(() => window.__SOURCE__.state.doc.toString()), /^Gamma! alpha/);
|
|
await page.getByRole('checkbox', { name: 'Regex' }).uncheck();
|
|
await find.fill('Gamma');
|
|
await page.getByRole('button', { name: 'Select all', exact: true }).click();
|
|
assert.equal(await page.evaluate(() => window.__SOURCE__.state.selection.ranges.length), 3);
|
|
await page.screenshot({ path: `${output}/source-${theme}.png` });
|
|
await find.focus(); await page.keyboard.press('Escape');
|
|
assert.equal(await find.count(), 0);
|
|
assert.equal(await page.evaluate(() => window.__SOURCE__.hasFocus), true);
|
|
await page.keyboard.press('Control+h');
|
|
assert.equal(await replace.evaluate(node => node === document.activeElement), true);
|
|
await find.fill('Gamma');
|
|
await page.keyboard.press('Enter');
|
|
await page.keyboard.press('F3');
|
|
await page.screenshot({ path: `${output}/source-replace-${theme}.png` });
|
|
await page.setViewportSize({ width: 800, height: 700 });
|
|
await onePanel();
|
|
assert.equal(await page.locator('.rs-find-bar').evaluate(node => node.scrollWidth <= node.clientWidth), true);
|
|
await page.screenshot({ path: `${output}/source-narrow-${theme}.png` });
|
|
await page.setViewportSize({ width: 1440, height: 1000 });
|
|
await find.focus(); await page.keyboard.press('Escape');
|
|
await page.evaluate(sample => { const view = window.__SOURCE__; view.dispatch({ changes: { from: 0, to: view.state.doc.length, insert: sample } }); }, sample);
|
|
await mode('Document view', 'Read');
|
|
await page.locator('.reading').focus();
|
|
await page.keyboard.press('Control+f');
|
|
await find.fill('Alpha'); await page.keyboard.press('Enter');
|
|
await onePanel();
|
|
assert.equal(await replace.count(), 0, 'Reading search does not offer replacement');
|
|
assert.equal(await page.evaluate(() => window.getSelection().toString()), 'Alpha');
|
|
const anchor = await page.evaluate(() => window.getSelection().anchorNode.parentElement.outerHTML);
|
|
await page.keyboard.press('Enter');
|
|
assert.notEqual(await page.evaluate(() => window.getSelection().anchorNode.parentElement.outerHTML), anchor);
|
|
await page.screenshot({ path: `${output}/reading-${theme}.png` });
|
|
await page.keyboard.press('Escape');
|
|
assert.equal(await page.locator('.reading').evaluate(node => node === document.activeElement), true);
|
|
await mode('Document view', 'Edit');
|
|
await mode('Editor layout', 'Writer');
|
|
}
|
|
console.log('PASS: one full-width document Find in Writer, nested table focus, IDE/source, and Reading, with replacement, regex, CRLF, focus return, both themes, and narrow controls.');
|
|
});
|