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.
82 lines
4.7 KiB
JavaScript
82 lines
4.7 KiB
JavaScript
// File tree drags into Writer and the IDE: documents become escaped links, images embed, and undo restores the source.
|
|
import assert from "node:assert/strict";
|
|
import { mockTauri, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
|
|
|
await runSmoke("links/fileDragLinks", async ({ page }) => {
|
|
await page.addInitScript(() => localStorage.setItem("runestone.settings", JSON.stringify({ autosaveEnabled: false })));
|
|
await mockTauri(page, {
|
|
commands: test => {
|
|
const svg = '<svg xmlns="http://www.w3.org/2000/svg" width="100" height="80"><rect width="100" height="80" fill="#639"/></svg>';
|
|
const workspace = test.workspace({
|
|
root: "C:\\file-drag-links",
|
|
files: { "notes/draft.md": "Before.\n\nAfter.\n", "files/report [Q1] (#1).pdf": "PDF fixture", "images/diagram (#1).svg": btoa(svg) },
|
|
});
|
|
return {
|
|
...workspace,
|
|
workspace_read_data_url: ({ rel }) => "data:image/svg+xml;base64," + workspace.files.get(rel),
|
|
plugins_snapshot: () => ({ plugins: [], issues: [] }),
|
|
spelling_menu_install: () => null,
|
|
};
|
|
},
|
|
});
|
|
const row = path => page.locator(`[data-tree-rel="${path}"]`);
|
|
async function drag(path, target) {
|
|
const from = await row(path).boundingBox(), to = await page.locator(target).boundingBox();
|
|
assert.ok(from && to, "The file and editor must be visible");
|
|
await page.mouse.move(from.x + Math.min(80, from.width / 2), from.y + from.height / 2);
|
|
await page.mouse.down();
|
|
await page.mouse.move(to.x + 45, to.y + 12, { steps: 15 });
|
|
await page.locator(".image-drop-target").waitFor();
|
|
await page.mouse.up();
|
|
}
|
|
const writerSource = () => page.evaluate(() => window.dragWriter.state.doc.toString());
|
|
const ideSource = () => page.evaluate(() => window.dragSource.state.doc.toString());
|
|
|
|
await page.goto(smokeUrl);
|
|
await row("notes").click();
|
|
await row("notes/draft.md").dblclick();
|
|
await page.locator(".cm-content").waitFor();
|
|
await page.evaluate(async () => {
|
|
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
|
|
window.dragWriter = EditorView.findFromDOM(document.querySelector(".cm-content"));
|
|
});
|
|
await row("files").click();
|
|
const original = await writerSource();
|
|
await drag("files/report [Q1] (#1).pdf", ".cm-content");
|
|
await page.waitForFunction(() => window.dragWriter.state.doc.toString().includes(".pdf)"));
|
|
const linked = await writerSource();
|
|
assert.ok(linked.includes("[report \\[Q1\\] (#1).pdf](../files/report%20%5BQ1%5D%20%28%231%29.pdf)"), linked);
|
|
assert.ok(!linked.includes(""));
|
|
await page.evaluate(() => window.dragWriter.focus());
|
|
await page.keyboard.press("Control+z");
|
|
assert.equal(await writerSource(), original);
|
|
console.log("PASS: Writer drags insert escaped document links and image embeds, and undo restores the source");
|
|
|
|
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");
|
|
window.dragSource = EditorView.findFromDOM(document.querySelector(".source-editor .cm-content"));
|
|
});
|
|
const originalIde = await ideSource();
|
|
await drag("files/report [Q1] (#1).pdf", ".source-editor .cm-content");
|
|
await page.waitForFunction(() => window.dragSource.state.doc.toString().includes(".pdf)"));
|
|
assert.ok((await ideSource()).includes("[report \\[Q1\\] (#1).pdf](../files/report%20%5BQ1%5D%20%28%231%29.pdf)"));
|
|
await page.evaluate(() => window.dragSource.focus());
|
|
assert.equal(await page.evaluate(() => window.dragSource.hasFocus), true);
|
|
await page.keyboard.press("Control+z");
|
|
await page.waitForFunction(expected => window.dragSource.state.doc.toString() === expected, originalIde, { timeout: 3000 });
|
|
assert.equal(await ideSource(), originalIde, "IDE undo restores the exact source");
|
|
await drag("images/diagram (#1).svg", ".source-editor .cm-content");
|
|
assert.ok((await ideSource()).includes(""));
|
|
assert.equal(await page.evaluate(() => window.__TEST__.calls.filter(call => ["workspace_rename", "workspace_write_bytes"].includes(call.command)).length), 0);
|
|
console.log("PASS: IDE drags insert escaped document links and image embeds, undo restores the source, and no file moves");
|
|
}, { timeout: 15000 });
|