Files
RuneStone/tests/smoke/editor/pasteRepeat.smoke.mjs
T
Knotty Wyvern 724402729e Replace Monaco with one CodeMirror editor and nest list items with Tab
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.
2026-10-28 10:48:44 -07:00

99 lines
4.9 KiB
JavaScript

// Repeated copy and paste of formatted Markdown stays exact across saves, tab switches, IDE switches, and line endings.
import assert from "node:assert/strict";
import { mockTauri, runSmoke, smokeUrl } from "../_harness/index.mjs";
await runSmoke("editor/pasteRepeat", 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({ expectedLength: expected.length, actualLength: (await writer()).length, errors: page.errors }); throw error; }
}
await page.goto(smokeUrl);
await page.getByText('smoke-workspace', { exact: true }).waitFor();
const formatted = '# Copied heading\n\n## Links\n\n[Reference](https://example.com) and [[second|Another note]]\n\n**Bold**, *italic*, and `code`.\n\n- A list item\n';
await page.evaluate(text => { window.__TEST__.files.set('notes/source.md', text); window.__TEST__.files.set('notes/pasted.md', ''); }, formatted);
await open('source.md');
await writer();
await page.locator('.cm-content').click();
await page.keyboard.press('Control+a');
await page.keyboard.press('Control+c');
await open('pasted.md');
await writer();
for (let iteration = 0; iteration < 12; iteration++) {
await page.locator('.cm-content').click();
await page.keyboard.press('Control+a');
await page.keyboard.press('Backspace');
await expectWriter('');
await page.keyboard.press('Control+v');
await expectWriter(formatted);
assert.equal(await page.locator('.live-writer .cm-editor').count(), 1, 'One mounted editor');
await page.keyboard.press('Control+s');
assert.equal(await page.evaluate(() => window.__TEST__.files.get('notes/pasted.md').replace(/\r\n?/g, '\n')), formatted);
if (iteration === 5) {
await page.keyboard.press('Control+e');
await page.locator('.source-editor .cm-content').waitFor();
await page.keyboard.press('Control+e');
await expectWriter(formatted);
}
await open('second.md');
await writer();
await page.getByRole('tab', { name: 'pasted.md', exact: true }).click();
await expectWriter(formatted);
}
// Clipboard formats can use different line endings than the destination.
for (const lineBreak of ['\n', '\r\n', '\r']) {
await page.evaluate(({ text, lineBreak }) => {
const view = window.__WRITER__;
view.dispatch({ selection: { anchor: 0, head: view.state.doc.length } });
const clipboardData = new DataTransfer();
clipboardData.setData('text/plain', text.replace(/\n/g, lineBreak));
view.contentDOM.dispatchEvent(new ClipboardEvent('paste', { bubbles: true, cancelable: true, clipboardData }));
}, { text: formatted, lineBreak });
await expectWriter(formatted);
assert.equal(await page.evaluate(() => window.__WRITER__.state.doc.lines), formatted.split('\n').length);
await page.keyboard.press('Control+s');
// The saved file keeps one line break. The Writer text with that line break is the saved source.
const synchronized = await page.evaluate(() => {
const saved = window.__TEST__.files.get('notes/pasted.md');
const lineBreak = saved.includes('\r\n') ? '\r\n' : '\n';
return window.__WRITER__.state.doc.sliceString(0, undefined, lineBreak) === saved;
});
assert.equal(synchronized, true, 'Writer and saved source agree');
}
console.log('PASS: formatted Markdown copied across notes stays exact through 12 paste/delete cycles, saves, tab reopen, IDE reopen, and LF/CRLF/CR clipboard replacement');
});