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.
This commit is contained in:
Knotty Wyvern
2026-10-28 10:48:44 -07:00
parent 80f5d908e0
commit 724402729e
70 changed files with 1583 additions and 1475 deletions
@@ -102,13 +102,13 @@ await runSmoke('appearance/backgroundFrames', async ({ browser }) => {
assert.deepEqual(await background.boundingBox(), beforeScroll);
await page.screenshot({ path: `${output}/${theme}-reader.png` });
await page.getByRole('button', { name: 'Split', exact: true }).click();
await page.locator('.monaco-editor').waitFor();
assert.equal(await style(page.locator('.monaco-editor-background').first(), 'backgroundColor'), 'rgba(0, 0, 0, 0)');
await page.locator('.source-editor .cm-content').waitFor();
assert.equal(await style(page.locator('.source-editor .cm-editor').first(), 'backgroundColor'), 'rgba(0, 0, 0, 0)');
await page.screenshot({ path: `${output}/${theme}-split.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('.monaco-editor').waitFor();
await page.locator('.source-editor .cm-content').waitFor();
await page.screenshot({ path: `${output}/${theme}-ide.png` });
await page.setViewportSize({ width: 680, height: 720 });
await page.getByRole('button', { name: 'Files', exact: true }).click();
@@ -37,11 +37,10 @@ await runSmoke('appearance/characterThemes', async ({ browser }) => {
await openFile(main, 'Theme.md');
await main.getByRole('textbox', { name: 'Writing editor', exact: true }).waitFor();
await openFile(ide, 'Theme.py');
await ide.locator('.monaco-editor textarea').waitFor();
const editorIds = () => ide.evaluate(async () => {
const { monaco } = await import('/src/lib/editor/monacoEnv.ts');
return monaco.editor.getEditors().filter(editor => editor.getDomNode()?.isConnected).map(editor => editor.getId());
});
await ide.locator('.source-editor .cm-content').waitFor();
// Mark each mounted editor once. A new editor has no mark, so it gets a new identifier.
const editorIds = () => ide.evaluate(() => [...document.querySelectorAll('.source-editor .cm-editor')]
.map(node => node.dataset.smokeId ||= String(window.__editorSerial = (window.__editorSerial || 0) + 1)));
const initialEditors = await editorIds();
const openSettings = async () => {
await settings.goto(`${smokeUrl}/?settingsWindow=true`);
@@ -108,7 +107,7 @@ await runSmoke('appearance/characterThemes', async ({ browser }) => {
await settings.waitForFunction(() => window.exportedTheme);
assert.deepEqual(await settings.evaluate(() => window.exportedTheme), template);
await ide.waitForFunction(expected => {
const spans = [...document.querySelectorAll('.view-line span')].filter(node => !node.children.length);
const spans = [...document.querySelectorAll('.source-editor .cm-line span')].filter(node => !node.children.length);
return Object.entries(expected).every(([text, color]) => {
const node = spans.find(node => node.textContent.replaceAll('\u00a0', ' ').includes(text));
const probe = document.createElement('i');
@@ -116,7 +115,7 @@ await runSmoke('appearance/characterThemes', async ({ browser }) => {
const target = getComputedStyle(probe).color; probe.remove();
return node && getComputedStyle(node).color === target;
});
}, { return: colors['syntax-keyword'], RuneStone: colors['syntax-string'], 42: colors['syntax-number'], print: colors['syntax-keyword'], '# Character colors': colors['syntax-comment'] });
}, { return: colors['syntax-keyword'], RuneStone: colors['syntax-string'], 42: colors['syntax-number'], print: colors['syntax-function'], '# Character colors': colors['syntax-comment'] });
assert.deepEqual(await editorIds(), initialEditors, 'Theme changes preserve the editor');
if (theme === 'harvest-moon') {
const normalized = await settings.evaluate(async () => {
@@ -147,17 +146,17 @@ await runSmoke('appearance/characterThemes', async ({ browser }) => {
assert.equal(await main.evaluate(() => window.getSelection().toString()), 'A calm surface with readable text.');
await main.screenshot({ path: path.join(output, `${theme}-${mode}-writer-selection.png`) });
await ide.evaluate(async () => {
const { monaco } = await import('/src/lib/editor/monacoEnv.ts');
const editor = monaco.editor.getEditors().find(editor => editor.getDomNode()?.isConnected);
editor.setSelection(new monaco.Selection(1, 1, 3, 21)); editor.focus();
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: 0, head: view.state.doc.line(3).from + 20 } }); view.focus();
});
await ide.locator('.selected-text').first().waitFor();
assert.equal(await ide.locator('.selected-text').first().evaluate(node => getComputedStyle(node).backgroundColor),
await ide.locator('.source-editor .cm-selectionBackground').first().waitFor();
assert.equal(await ide.locator('.source-editor .cm-selectionBackground').first().evaluate(node => getComputedStyle(node).backgroundColor),
warmFill, 'IDE selection uses the same warm fill');
await ide.screenshot({ path: path.join(output, `${theme}-${mode}-ide-selection.png`) });
await ide.evaluate(async () => {
const { monaco } = await import('/src/lib/editor/monacoEnv.ts');
monaco.editor.getEditors().find(editor => editor.getDomNode()?.isConnected).setPosition({ lineNumber: 1, column: 1 });
const { EditorView } = await import('/node_modules/@codemirror/view/dist/index.js');
EditorView.findFromDOM(document.querySelector('.source-editor .cm-content')).dispatch({ selection: { anchor: 0 } });
});
}
await ide.screenshot({ path: path.join(output, `${theme}-${mode}-ide.png`) });
+1 -1
View File
@@ -75,7 +75,7 @@ await runSmoke("appearance/density", async ({ page }) => {
await documentView().press("Home");
}
await editorLayout().press("Home");
await page.locator(".monaco-editor").waitFor();
await page.locator(".source-editor .cm-content").waitFor();
await page.locator(".line-history").waitFor();
await page.evaluate(() => window.removeGit());
await page.locator(".line-history").waitFor({ state: "hidden" });
+16 -19
View File
@@ -1,4 +1,4 @@
// Built-in palettes: modes, light-only Sakura, migration, persistence, typography, cross-window sync, Monaco updates, and narrow settings.
// Built-in palettes: modes, light-only Sakura, migration, persistence, typography, cross-window sync, source editor updates, and narrow settings.
import assert from "node:assert/strict";
import path from "node:path";
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
@@ -28,24 +28,21 @@ await runSmoke("appearance/palettes", async ({ browser }) => {
await main.getByRole("textbox", { name: "Find a file" }).fill(`theme-${index}.py`);
await main.getByRole("dialog").getByRole("button").filter({ hasText: `theme-${index}.py` }).first().waitFor();
await main.getByRole("textbox", { name: "Find a file" }).press("Enter");
await main.locator(".monaco-editor textarea").waitFor();
await main.waitForFunction(async file => {
const { monaco } = await import("/src/lib/editor/monacoEnv.ts");
return monaco.editor.getEditors().some(editor => editor.getDomNode()?.isConnected && editor.getModel()?.uri.path.endsWith(file));
}, `theme-${index}.py`);
await main.locator(".view-line").filter({ hasText: `Theme sample ${index}` }).waitFor();
await main.locator(".source-editor .cm-content").waitFor();
await main.waitForFunction(file => document.querySelector(".editor .breadcrumb")?.textContent.endsWith(file)
&& document.querySelector(".source-editor .cm-content")?.dataset.language === "python", `theme-${index}.py`);
await main.locator(".source-editor .cm-line").filter({ hasText: `Theme sample ${index}` }).waitFor();
}
async function editorIds() {
return main.evaluate(async () => {
const { monaco } = await import("/src/lib/editor/monacoEnv.ts");
return monaco.editor.getEditors().filter(editor => editor.getDomNode()?.isConnected).map(editor => editor.getId());
});
// Mark each mounted editor once. A new editor has no mark, so it gets a new identifier.
return main.evaluate(() => [...document.querySelectorAll(".source-editor .cm-editor")]
.map(node => node.dataset.smokeId ||= String(window.__editorSerial = (window.__editorSerial || 0) + 1)));
}
// Wait until "RuneStone", "print", and "42" have three distinct syntax colors.
// Wait until "RuneStone", "def", and "42" have three distinct syntax colors.
async function waitForSyntax() {
await main.waitForFunction(() => {
const spans = [...document.querySelectorAll(".view-line span")];
const colors = ["RuneStone", "print", "42"].map(text => {
const spans = [...document.querySelectorAll(".source-editor .cm-line span")];
const colors = ["RuneStone", "def", "42"].map(text => {
const span = spans.find(node => !node.children.length && node.textContent.includes(text));
return span ? getComputedStyle(span).color : null;
});
@@ -79,7 +76,7 @@ await runSmoke("appearance/palettes", async ({ browser }) => {
document.body.append(probe);
const expected = getComputedStyle(probe).backgroundColor;
probe.remove();
const surfaces = [...document.querySelectorAll(".monaco-editor .monaco-editor-background")];
const surfaces = [...document.querySelectorAll(".source-editor .cm-editor")];
const workarea = document.querySelector(".editor > .body");
return surfaces.length > 0 && surfaces.every(element => getComputedStyle(element).backgroundColor === "rgba(0, 0, 0, 0)")
&& workarea && getComputedStyle(workarea).backgroundColor === expected;
@@ -94,16 +91,16 @@ await runSmoke("appearance/palettes", async ({ browser }) => {
const before = await editorIds();
await choose(settings, theme, mode);
backgrounds.add(await expectAppearance(theme, mode));
assert.deepEqual(await editorIds(), before, "Existing Monaco editors keep their identity when a theme changes");
assert.deepEqual(await editorIds(), before, "Existing source editors keep their identity when a theme changes");
await openCode(nextCode++);
assert.notDeepEqual(await editorIds(), before, "A new file creates a new Monaco editor");
assert.notDeepEqual(await editorIds(), before, "A new file creates a new source editor");
await expectAppearance(theme, mode);
await waitForSyntax();
assert.deepEqual(await settings.evaluate(() => window.__TEST__.settings("appearance")), { theme, mode });
await settings.screenshot({ path: path.join(output, `appearance-${theme}-${mode}.png`) });
await main.screenshot({ path: path.join(output, `appearance-editor-${theme}-${mode}.png`) });
if (theme === "sakura") {
const keywordColor = await main.locator(".view-line span").evaluateAll(spans => {
const keywordColor = await main.locator(".source-editor .cm-line span").evaluateAll(spans => {
const keyword = spans.find(span => !span.children.length && span.textContent.trim() === "def");
return keyword ? getComputedStyle(keyword).color : null;
});
@@ -120,7 +117,7 @@ await runSmoke("appearance/palettes", async ({ browser }) => {
assert.match(typography.heading, /Poppins.*Arial/);
assert.equal(await settings.evaluate(() => getComputedStyle(document.documentElement).getPropertyValue("--rs-accent").trim()), "#d97757");
} else assert.doesNotMatch(typography.body, /Lora|Georgia/);
console.log(`PASS: ${theme} ${mode}, saved state, cross-window selection, existing and new Monaco editors`);
console.log(`PASS: ${theme} ${mode}, saved state, cross-window selection, existing and new source editors`);
}
}
assert.equal(backgrounds.size, 5, "All supported combinations have distinct backgrounds");
+3 -3
View File
@@ -97,13 +97,13 @@ await runSmoke("editor/emptyMenu", async ({ page }) => {
}
await page.getByRole('group',{name:'Editor layout'}).hover();
await page.getByRole('button',{name:'IDE',exact:true}).click();
await page.locator('.monaco-editor').waitFor();
await page.locator('.monaco-editor textarea').focus();
await page.locator('.source-editor .cm-content').waitFor();
await page.locator('.source-editor .cm-content').focus();
await page.keyboard.press('Shift+F10');
await menu().waitFor();
await menu().getByRole('menuitem',{name:'Add external link',exact:true}).click();
assert.equal(await page.getByRole('dialog').count(),0);
await page.locator('.monaco-editor textarea').focus();
await page.locator('.source-editor .cm-content').focus();
await page.keyboard.press('Control+a');
await page.keyboard.press('Backspace');
await page.keyboard.press('Shift+F10');
+2 -2
View File
@@ -108,10 +108,10 @@ await runSmoke("editor/footnotes", async ({ page }) => {
const pane = button.closest('.reading').parentElement.getBoundingClientRect();
return bounds.left >= pane.left && bounds.right <= pane.right;
}));
assert.equal(await page.getByText("Child content.", { exact: true }).isVisible(), false);
assert.equal(await page.locator(".md-page").getByText("Child content.", { exact: true }).isVisible(), false);
await page.screenshot({ path: `${output}/reader-${theme}-narrow.png` });
await page.keyboard.press("Space");
assert.equal(await page.getByText("Child content.", { exact: true }).isVisible(), true);
assert.equal(await page.locator(".md-page").getByText("Child content.", { exact: true }).isVisible(), true);
await page.getByRole("button", { name: "Collapse Last section", exact: true }).click();
await page.locator(".md-footnote-ref a").first().click();
assert.equal(await page.locator(".md-footnotes").isVisible(), true);
+2 -2
View File
@@ -146,8 +146,8 @@ await runSmoke("editor/imageNavigation", async ({ page }) => {
// The layout switcher names its buttons by mode (src/lib/layout/EditorPane.svelte:200-208, src/lib/ui/ModeSwitcher.svelte:96).
await page.getByRole("group", { name: "Editor layout", exact: true }).hover();
await page.getByRole("button", { name: "IDE", exact: true }).click();
await page.locator(".monaco-editor textarea").waitFor();
await dragFromTree(".monaco-editor .view-lines");
await page.locator(".source-editor .cm-content").waitFor();
await dragFromTree(".source-editor .cm-content");
await page.keyboard.press("Control+s");
await page.waitForFunction(() => window.__TEST__.files.get("notes/welcome.md").includes("picture%20"));
assert.equal(await page.evaluate(() => window.__TEST__.calls.filter(c => c.command === "workspace_write_bytes").length), 0);
+10 -10
View File
@@ -149,24 +149,24 @@ await runSmoke("editor/images", async ({ page }) => {
await page.getByRole("group", { name: "Document view" }).getByRole("button", { name: "Read", exact: true }).focus();
await page.keyboard.press("Home");
await page.keyboard.press("Control+e");
await page.locator(".monaco-editor textarea").waitFor();
await page.locator(".source-editor .cm-content").waitFor();
await page.evaluate(async () => {
const { monaco } = await import("/src/lib/editor/monacoEnv.ts");
window.__MONACO__ = monaco.editor.getEditors().find(editor => editor.getDomNode()?.isConnected);
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
window.__CM__ = EditorView.findFromDOM(document.querySelector(".source-editor .cm-content"));
});
const sourceBefore = await page.evaluate(() => window.__MONACO__.getValue());
await drop(2, ".monaco-editor .view-lines");
await page.waitForFunction(() => (window.__MONACO__.getValue().match(/!\[\]/g) || []).length === 5);
const sourceBefore = await source();
await drop(2, ".source-editor .cm-content");
await page.waitForFunction(() => (window.__CM__.state.doc.toString().match(/!\[\]/g) || []).length === 5);
await page.keyboard.press("Control+z");
assert.equal(await page.evaluate(() => window.__MONACO__.getValue()), sourceBefore);
assert.equal(await source(), sourceBefore);
await page.keyboard.press("Control+y");
assert.equal((await save()).match(/!\[\]/g).length, 5);
// A failed write leaves source unchanged and surfaces an error.
const beforeFailure = await page.evaluate(() => window.__MONACO__.getValue());
const beforeFailure = await source();
await page.evaluate(() => { window.__TEST__.failWrite = true; });
await drop(1, ".monaco-editor .view-lines");
await drop(1, ".source-editor .cm-content");
await page.getByText("Image write failed", { exact: true }).waitFor();
assert.equal(await page.evaluate(() => window.__MONACO__.getValue()), beforeFailure);
assert.equal(await source(), beforeFailure);
await page.evaluate(() => { window.__TEST__.failWrite = false; });
// File drops over a rendered widget are handled by the editor's capture listener.
+8 -9
View File
@@ -77,20 +77,19 @@ await runSmoke("editor/interactions", async ({ page }) => {
await page.locator('.writer-link[data-href="https://example.com"]').click({ modifiers: ["Control"] });
await page.waitForFunction(() => window.__TEST__.calls.some(call => call.command === "plugin:opener|open_url" && call.args.url === "https://example.com"));
await page.keyboard.press("Control+e");
await page.locator(".monaco-editor").waitFor();
await page.locator(".source-editor .cm-content").waitFor();
const linkPoint = await page.evaluate(async () => {
const { monaco } = await import("/src/lib/editor/monacoEnv.ts");
const view = monaco.editor.getEditors().find(view => view.getDomNode()?.isConnected);
const position = view.getModel().getPositionAt(view.getValue().indexOf("[Local]") + 3);
view.revealPositionInCenter(position);
view.setPosition(position); view.focus();
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
const view = EditorView.findFromDOM(document.querySelector(".source-editor .cm-content"));
const position = view.state.doc.toString().indexOf("[Local]") + 3;
view.dispatch({ selection: { anchor: position }, scrollIntoView: true }); view.focus();
return position;
});
await page.waitForTimeout(300);
const point = await page.evaluate(async position => {
const { monaco } = await import("/src/lib/editor/monacoEnv.ts");
const view = monaco.editor.getEditors().find(view => view.getDomNode()?.isConnected), rect = view.getDomNode().getBoundingClientRect(), coords = view.getScrolledVisiblePosition(position);
return { x: rect.left + coords.left + 2, y: rect.top + coords.top + coords.height / 2 };
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
const coords = EditorView.findFromDOM(document.querySelector(".source-editor .cm-content")).coordsAtPos(position);
return { x: coords.left + 2, y: (coords.top + coords.bottom) / 2 };
}, linkPoint);
await page.keyboard.down("Control"); await page.mouse.click(point.x, point.y); await page.keyboard.up("Control");
await page.waitForFunction(() => document.querySelector('[role="tab"][aria-selected="true"]')?.textContent.includes("other.md"));
+118
View File
@@ -0,0 +1,118 @@
// List nesting: Tab and Shift+Tab in Write, nested labels in Write and Read, one undo history in Write and Source, and the 4-space indent in Source.
import assert from "node:assert/strict";
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
await runSmoke("editor/listNesting", async ({ page }) => {
await mockTauri(page, {
commands: test => ({
...test.workspace({
root: "C:\\smoke-workspace",
files: {
"notes/readme.md": "# Requirements\n\n1. Topic\n2. \n3. A\n",
"src/hello.py": "print('hello')\n",
},
}),
spelling_menu_install: () => null,
}),
});
const output = await outputDir("editor/listNesting");
await page.goto(smokeUrl);
await page.getByText("smoke-workspace", { exact: true }).waitFor();
async function open(name, editor) {
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();
await page.getByRole("textbox", { name: editor, exact: true }).waitFor();
await page.evaluate(async () => {
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
window.__CM__ = EditorView.findFromDOM(document.querySelector(".cm-content"));
});
}
const doc = () => page.evaluate(() => window.__CM__.state.doc.toString());
const caretAt = (text, offset = text.length) => page.evaluate(([text, offset]) => {
window.__CM__.dispatch({ selection: { anchor: window.__CM__.state.doc.toString().indexOf(text) + offset } });
window.__CM__.focus();
}, [text, offset]);
const labels = () => page.locator(".live-writer .writer-list-label").allTextContents();
await open("readme.md", "Writing editor");
await caretAt("2. ");
await page.keyboard.press("Tab");
assert.equal(await doc(), "# Requirements\n\n1. Topic\n 1. \n2. A\n", "Tab nests the empty item and renumbers the next item");
assert.deepEqual(await labels(), ["a."], "The nested item shows a letter before it has text");
await page.keyboard.type("Sub item");
await page.keyboard.press("Enter");
await page.keyboard.type("Second");
assert.equal(await doc(), "# Requirements\n\n1. Topic\n 1. Sub item\n 2. Second\n2. A\n");
assert.deepEqual(await labels(), ["a.", "b."]);
for (const width of [1440, 600]) {
if (width === 600) {
await page.getByRole("button", { name: "Files", exact: true }).click();
await page.getByRole("button", { name: "Hide outline", exact: true }).click();
}
await page.setViewportSize({ width, height: 800 });
for (const mode of ["dark", "light"]) {
await page.evaluate(async mode => (await import("/src/lib/theme/appearance.ts")).saveAppearance({ theme: "default", mode }), mode);
await page.locator(".live-writer .cm-content").screenshot({ path: `${output}/writer-${mode}-${width}.png` });
}
}
await page.setViewportSize({ width: 1440, height: 900 });
await page.locator(".live-writer .cm-content").focus();
await page.keyboard.press("Shift+Tab");
assert.equal(await doc(), "# Requirements\n\n1. Topic\n 1. Sub item\n2. Second\n3. A\n", "Shift+Tab moves the item up and renumbers the outer list");
assert.deepEqual(await labels(), ["a."]);
await page.keyboard.press("Control+z");
assert.equal(await doc(), "# Requirements\n\n1. Topic\n 1. Sub item\n 2. Second\n2. A\n", "One undo step restores the nesting and the numbers");
await caretAt("1. Topic");
await page.keyboard.press("Tab");
assert.equal(await doc(), "# Requirements\n\n1. Topic\n 1. Sub item\n 2. Second\n2. A\n", "The first item stays in place");
await page.getByRole("group", { name: "Document view" }).hover();
await page.getByRole("button", { name: "Read", exact: true }).click();
await page.locator(".md-page ol ol").waitFor();
assert.equal(await page.locator(".md-page ol ol").evaluate(list => getComputedStyle(list).listStyleType), "lower-alpha");
assert.equal(await page.locator(".md-page > .reading > ol, .md-page ol").first().evaluate(list => getComputedStyle(list).listStyleType), "decimal");
await page.locator(".md-page").screenshot({ path: `${output}/reader.png` });
await page.getByRole("group", { name: "Document view" }).hover();
await page.getByRole("button", { name: "Edit", exact: true }).click();
await page.getByRole("textbox", { name: "Writing editor", exact: true }).waitFor();
// Write and Source share the undo history of the document.
await caretAt("2. A");
await page.keyboard.type(" more");
await page.keyboard.press("Control+e");
await page.locator('.source-editor[data-chrome="Ide"] .cm-gutters').waitFor();
assert.equal(await page.locator(".source-editor .cm-content").getAttribute("data-language"), "markdown");
await page.locator(".source-editor .cm-content").focus();
await page.keyboard.press("Control+z");
assert.equal(await doc(), "# Requirements\n\n1. Topic\n 1. Sub item\n 2. Second\n2. A\n", "Source undoes the last edit from Write");
await page.keyboard.press("Control+Shift+KeyZ");
assert.equal(await doc(), "# Requirements\n\n1. Topic\n 1. Sub item\n 2. Second\n2. A more\n");
await caretAt("2. A more");
await page.keyboard.press("Tab");
assert.equal(await doc(), "# Requirements\n\n1. Topic\n 1. Sub item\n 2. Second\n 3. A more\n", "Tab nests list items in Source too");
await page.keyboard.press("Control+e");
await page.getByRole("textbox", { name: "Writing editor", exact: true }).waitFor();
assert.deepEqual(await labels(), ["a.", "b.", "c."]);
// Source indents code to the next 4-column stop.
await open("hello.py", "Editor");
await caretAt("print", 0);
await page.keyboard.press("Tab");
assert.equal(await doc(), " print('hello')\n");
await caretAt("print", 2);
await page.keyboard.press("Tab");
assert.equal(await doc(), " pr int('hello')\n", "Tab inside a line fills to the next stop");
await page.keyboard.press("Control+z");
await page.keyboard.press("Control+z");
assert.equal(await doc(), "print('hello')\n");
await page.locator(".source-editor").screenshot({ path: `${output}/source-ide.png` });
// The history of a document stays while its tab stays open.
await open("readme.md", "Writing editor");
await page.locator(".live-writer .cm-content").focus();
await page.keyboard.press("Control+z");
assert.equal(await doc(), "# Requirements\n\n1. Topic\n 1. Sub item\n 2. Second\n2. A more\n", "Undo after a tab change reverts the Tab from Source");
console.log("PASS: Tab and Shift+Tab nesting, renumbering, Write labels, Read letters, shared undo in Write and Source and across tabs, Source list Tab, and 4-space code indent.");
});
+7 -7
View File
@@ -32,21 +32,21 @@ await runSmoke("editor/markdownMenu", async ({ page }) => {
await page.getByRole("dialog").getByRole("button").filter({ hasText: name }).first().click();
await page.getByRole("tab", { selected: true }).click({ button: "right" });
await page.getByRole("menuitem", { name: "Source mode", exact: true }).click();
await page.locator(".monaco-editor textarea").waitFor();
await page.locator(".source-editor .cm-content").waitFor();
}
async function waitForText(text) {
await page.evaluate(async () => { window.__MONACO__ = (await import("/src/lib/editor/monacoEnv.ts")).monaco; });
await page.waitForFunction(expected => window.__MONACO__.editor.getEditors().some(editor => editor.getDomNode()?.isConnected && editor.getValue() === expected), text);
await page.evaluate(async () => { window.__EditorView = (await import("/node_modules/@codemirror/view/dist/index.js")).EditorView; });
await page.waitForFunction(expected => [...document.querySelectorAll(".cm-content")].some(node => window.__EditorView.findFromDOM(node)?.state.doc.toString() === expected), text);
}
await page.goto(smokeUrl);
await page.getByText("smoke-workspace", { exact: true }).waitFor();
await quickOpen("welcome.md");
const source = "First paragraph.\n\nSecond paragraph.\n";
await page.evaluate(async value => {
const { monaco } = await import("/src/lib/editor/monacoEnv.ts");
const editor = monaco.editor.getEditors().find(editor => editor.getDomNode()?.isConnected);
editor.setValue(value);
editor.setSelection(new monaco.Selection(1, 1, 1, 6)); editor.focus();
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
const view = EditorView.findFromDOM(document.querySelector(".source-editor .cm-content"));
view.dispatch({ changes: { from: 0, to: view.state.doc.length, insert: value } });
view.dispatch({ selection: { anchor: 0, head: 5 } }); view.focus();
}, source);
const menu = page.getByRole("menu", { name: "Markdown text actions", exact: true });
await page.keyboard.press("Shift+F10");
+3 -1
View File
@@ -34,7 +34,9 @@ await runSmoke("editor/markdownPaste", async ({ page }) => {
clipboardData.setData("text/plain", source);
view.contentDOM.dispatchEvent(new ClipboardEvent("paste", { bubbles: true, cancelable: true, clipboardData }));
view.dispatch({ selection: { anchor: 0 } });
const { forceParsing, syntaxTree } = await import("/node_modules/.vite/deps/@codemirror_language.js");
// Import the module URL that the app loaded, so the language state is the same instance.
const languageUrl = performance.getEntriesByType("resource").map(entry => entry.name).find(name => new URL(name).pathname === "/node_modules/.vite/deps/@codemirror_language.js");
const { forceParsing, syntaxTree } = await import(languageUrl);
forceParsing(view, view.state.doc.length, 5000);
const nodes = [];
syntaxTree(view.state).iterate({ enter(node) { if (node.name === "StrongEmphasis") nodes.push(node.from); } });
+7 -7
View File
@@ -65,7 +65,7 @@ await runSmoke("editor/pasteRepeat", async ({ page }) => {
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('.monaco-editor textarea').waitFor();
await page.locator('.source-editor .cm-content').waitFor();
await page.keyboard.press('Control+e');
await expectWriter(formatted);
}
@@ -86,13 +86,13 @@ await runSmoke("editor/pasteRepeat", async ({ page }) => {
await expectWriter(formatted);
assert.equal(await page.evaluate(() => window.__WRITER__.state.doc.lines), formatted.split('\n').length);
await page.keyboard.press('Control+s');
const synchronized = await page.evaluate(async () => {
const { monaco } = await import('/src/lib/editor/monacoEnv.ts');
const model = monaco.editor.getModels().find(model => model.uri.path.endsWith('/pasted.md'));
const source = window.__WRITER__.state.doc.sliceString(0, undefined, model.getEOL());
return source === model.getValue() && source === window.__TEST__.files.get('notes/pasted.md');
// 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, model, and saved source agree');
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');
});
+18 -33
View File
@@ -1,4 +1,4 @@
// Editor menu surfaces: Writer, spelling, IDE, and code menus share the file menu styles; code tint and the command palette match in both themes.
// 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";
@@ -93,59 +93,44 @@ await runSmoke("editor/surfaces", async ({ page }) => {
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('.monaco-editor').waitFor();
await page.locator('.monaco-host').click({ button: 'right', position: { x: 500, y: 400 } });
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('.monaco-host').click({ button: 'right', position: { x: 500, y: 400 } });
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');
assert.equal(await page.locator('.monaco-menu').count(), 0);
// 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 page.getByRole('menuitem', { name: 'Command palette F1', exact: true }).click();
const palette = page.locator('.quick-input-widget');
await palette.waitFor({ state: 'visible' });
const paletteMetrics = () => palette.evaluate(node => {
const row = node.querySelector('.monaco-list-row.focused');
const field = node.querySelector('.monaco-inputbox');
const a = getComputedStyle(row), b = getComputedStyle(field);
const probe = document.createElement('div');
probe.style.background = 'var(--rs-item-selection-bg)'; probe.style.color = 'var(--rs-item-selection-border)';
node.append(probe); const expected = getComputedStyle(probe);
const result = { fill: a.backgroundColor, expectedFill: expected.backgroundColor, outline: a.outlineColor, expectedOutline: expected.color, radius: a.borderRadius, inputRadius: b.borderRadius, inputOutline: b.outlineColor, inputOutlineWidth: b.outlineWidth };
probe.remove(); return result;
});
let p = await paletteMetrics();
assert.equal(p.fill, p.expectedFill);
assert.equal(p.outline, p.expectedOutline);
assert.equal(p.radius, '5px'); assert.equal(p.inputRadius, '5px');
assert.equal(p.inputOutline, p.expectedOutline); assert.equal(p.inputOutlineWidth, '2px');
await page.keyboard.press('ArrowDown');
p = await paletteMetrics(); assert.equal(p.fill, p.expectedFill);
await page.screenshot({ path: `${output}/palette-${theme}.png` });
await page.keyboard.press('Escape');
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('.monaco-host').click({ button: 'right', position: { x: 100, y: 300 } });
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: 'Command palette F1', exact: true }).evaluate(n => n === document.activeElement), true);
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 palette.waitFor({ state: 'visible' });
await page.screenshot({ path: `${output}/palette-narrow-${theme}.png` });
await page.keyboard.press('Escape');
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', 'palette selection/focus', 'narrow keyboard menu/palette'], nativeDesktop: 'not tested' });
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 });
+9 -12
View File
@@ -68,22 +68,21 @@ await runSmoke("editor/undoHistory", async ({ page }) => {
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('.monaco-editor textarea').waitFor();
await page.locator('.source-editor .cm-content').waitFor();
await page.evaluate(async () => {
const { monaco } = await import('/src/lib/editor/monacoEnv.ts');
const editor = monaco.editor.getEditors().find(view => view.getDomNode()?.isConnected);
editor.setPosition({ lineNumber: editor.getModel().getLineCount(), column: editor.getModel().getLineMaxColumn(editor.getModel().getLineCount()) });
editor.focus();
window.__IDE__ = editor;
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__.getDomNode()?.isConnected), true, 'Typing keeps the same IDE editor mounted');
assert.equal(await page.evaluate(() => window.__IDE__.getValue()), original + ' first edit second edit');
assert.equal(await page.evaluate(() => window.__IDE__.dom.isConnected), true, 'Typing keeps the same IDE 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();
await page.keyboard.press('Control+z');
await expectWriter(original + ' first edit second');
// 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');
@@ -91,8 +90,6 @@ await runSmoke("editor/undoHistory", async ({ page }) => {
await page.keyboard.press('Control+y');
await expectWriter(original + ' first edit');
await page.keyboard.press('Control+y');
await expectWriter(original + ' first edit second');
await page.keyboard.press('Control+y');
await expectWriter(original + ' first edit second edit');
console.log('PASS: Writer undo includes edits from IDE mode');
const tableSource = '# Table\n\n| A | B |\n| --- | --- |\n| One | Two |\n\nTail.\n';
+15 -14
View File
@@ -36,17 +36,17 @@ await runSmoke("find/documentFind", async ({ page }) => {
}
async function onePanel() {
assert.equal(await page.locator('.rs-find-bar:visible').count(), 1);
assert.equal(await page.locator('.find-widget.visible').count(), 0, 'No Monaco floating find widget');
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('.monaco-editor'));
await page.waitForFunction(() => !!document.querySelector('.source-editor .cm-content'));
return page.evaluate(async () => {
const { monaco } = await import('/src/lib/editor/monacoEnv.ts');
window.__MONACO__ = monaco.editor.getEditors().find(view => view.getDomNode()?.isConnected && view.getDomNode().getBoundingClientRect().width > 0);
window.__MONACO__.focus();
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);
@@ -84,21 +84,22 @@ await runSmoke("find/documentFind", async ({ page }) => {
await page.keyboard.press('Escape');
await mode('Editor layout', 'IDE');
await sourceEditor();
await page.evaluate(() => { window.__MONACO__.getModel().setValue('Alpha alpha alphabet\r\nAlpha second\r\nAlpha third'); window.__MONACO__.setPosition({ lineNumber: 1, column: 1 }); });
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 first = await page.evaluate(() => window.__MONACO__.getSelection().toString());
const selection = () => page.evaluate(() => JSON.stringify(window.__SOURCE__.state.selection.main));
const first = await selection();
await page.keyboard.press('Enter');
assert.notEqual(await page.evaluate(() => window.__MONACO__.getSelection().toString()), first);
assert.notEqual(await selection(), first);
await page.keyboard.press('Shift+Enter');
assert.equal(await page.evaluate(() => window.__MONACO__.getSelection().toString()), first);
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.__MONACO__.getValue().replace(/\r\n/g, '\n')), 'Gamma alpha alphabet\nGamma second\nGamma third');
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');
@@ -107,15 +108,15 @@ await runSmoke("find/documentFind", async ({ page }) => {
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.__MONACO__.getValue()), /^Gamma! alpha/);
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.__MONACO__.getSelections().length), 3);
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.__MONACO__.hasTextFocus()), true);
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');
@@ -128,7 +129,7 @@ await runSmoke("find/documentFind", async ({ page }) => {
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 => window.__MONACO__.getModel().setValue(sample), sample);
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');
+1 -1
View File
@@ -40,7 +40,7 @@ await runSmoke("layout/outline", async ({ browser }) => {
await page.locator(".cm-content").waitFor();
await page.getByRole("button", { name: "Hide outline", exact: true }).click();
await page.keyboard.press("Control+e");
await page.locator(".monaco-editor").waitFor();
await page.locator(".source-editor .cm-content").waitFor();
assert.equal(await page.locator(".right").count(), 0);
await page.keyboard.press("Control+e");
await page.locator(".cm-content").waitFor();
+12 -6
View File
@@ -67,11 +67,11 @@ await runSmoke("layout/splits", async ({ page }) => {
assert.equal(await page.evaluate(()=>window.__TEST__.writes.includes('a.md')),false,'Save uses the focused right pane');
await focus('a.md'); await page.keyboard.press('Control+s'); await page.waitForFunction(()=>window.__TEST__.writes.includes('a.md'));
await pane('notes/b.md').getByRole('group',{name:'Editor layout',exact:true}).hover();
await pane('notes/b.md').getByRole('button',{name:'IDE',exact:true}).click(); await pane('notes/b.md').locator('.monaco-editor').waitFor();
await pane('notes/b.md').getByRole('button',{name:'IDE',exact:true}).click(); await pane('notes/b.md').locator('.source-editor .cm-content').waitFor();
assert.equal(await pane('a.md').locator('.cm-content').count(),1,'Changing the right mode keeps the left editor');
await openRight('a.md','Right note');
assert.equal(await page.locator('.document-pane').count(),2);
await page.waitForFunction(async()=>{const {monaco}=await import('/src/lib/editor/monacoEnv.ts');return monaco.editor.getEditors().some(editor=>editor.getModel()?.uri.path.endsWith('/b.md') && editor.hasTextFocus());}); await page.keyboard.press('Control+End'); await page.keyboard.type('\nIDE edit.'); await page.keyboard.press('Control+s');
await page.waitForFunction(()=>!!document.activeElement?.matches('[data-document-path="notes/b.md"] .source-editor .cm-content')); await page.keyboard.press('Control+End'); await page.keyboard.type('\nIDE edit.'); await page.keyboard.press('Control+s');
await page.waitForFunction(()=>window.__TEST__.files.get('notes/b.md').includes('IDE edit.'));
await pane('notes/b.md').getByRole('group',{name:'Editor layout',exact:true}).hover();
await pane('notes/b.md').getByRole('button',{name:'Writer',exact:true}).click(); await pane('notes/b.md').locator('.cm-content').waitFor();
@@ -85,7 +85,8 @@ await runSmoke("layout/splits", async ({ page }) => {
for(const path of ['a.md','notes/b.md']) await pane(path).locator('.cm-content').evaluate(async node=> {
const {EditorView}=await import('/node_modules/@codemirror/view/dist/index.js'); const v=EditorView.findFromDOM(node); const source=v.state.doc.toString(); const from=source.indexOf(source.includes('Alpha') ? 'Origin' : 'Second'); v.dispatch({selection:{anchor:from,head:from+6}});
});
const selections=await page.evaluate(async()=> { const {monaco}=await import('/src/lib/editor/monacoEnv.ts'); const resource=performance.getEntriesByType('resource').find(entry=>new URL(entry.name).pathname==='/src/lib/editor/selection.ts'); const {selectedEditorText}=await import(resource.name); return monaco.editor.getModels().map(model=>selectedEditorText(model.uri.path.split('/')[1])).filter(Boolean).sort(); });
// Read the selection of each pane editor. Each editor keeps its own selection.
const selections=(await Promise.all(['a.md','notes/b.md'].map(path=>pane(path).locator('.cm-content').evaluate(async node=> { const {EditorView}=await import('/node_modules/@codemirror/view/dist/index.js'); const {state}=EditorView.findFromDOM(node); return state.sliceDoc(state.selection.main.from,state.selection.main.to); })))).filter(Boolean).sort();
assert.deepEqual(selections,['Origin','Second'],'Each pane retains its own selection');
await openRight('a.md','Right note'); assert.equal(await page.locator('.document-pane').count(),2);
await page.waitForFunction(()=>document.activeElement?.closest('[data-document-path]')?.dataset.documentPath==='notes/b.md');
@@ -99,7 +100,7 @@ await runSmoke("layout/splits", async ({ page }) => {
await pane('notes/b.md').getByRole('button',{name:'Close split',exact:true}).click();
assert.equal(await page.locator('.document-pane').count(),1); assert.equal(await pane('a.md').count(),1);
assert.match(await text('a.md'),/Left unsaved/);
assert.equal(await page.evaluate(async()=> { const {monaco}=await import('/src/lib/editor/monacoEnv.ts'); return monaco.editor.getModels().length; }),2,'Closing a split preserves both tab models');
assert.equal(await page.getByRole('tab').count(),2,'Closing a split preserves both tabs');
await page.getByRole('tab',{name:/b.md/}).click(); await pane('notes/b.md').locator('.cm-content').waitFor();
assert.match(await text('notes/b.md'),/Right still unsaved/,'The closed split retains its unsaved buffer');
await page.getByRole('tab',{name:/a.md/}).click(); await openRight('a.md','Right note'); await pane('notes/b.md').locator('.cm-content').waitFor();
@@ -139,6 +140,11 @@ await runSmoke("layout/splits", async ({ page }) => {
await page.keyboard.press('Control+w'); await pane('notes/b.md').waitFor({state:'detached'});
await focus('a.md'); await append('a.md','\nOther tab closed.'); await page.keyboard.press('Control+s');
await page.waitForFunction(()=>window.__TEST__.files.get('a.md').includes('Other tab closed.'));
assert.equal(await page.evaluate(async()=>{const {monaco}=await import('/src/lib/editor/monacoEnv.ts');return monaco.editor.getModels().some(model=>model.uri.path.endsWith('/b.md'));}),false,'Closing the tab releases only its model');
console.log(JSON.stringify({passed:['independent Writer/IDE/Reading modes','dirty close cancellation and model release','independent edits and saves','per-pane selections','focus existing duplicate target','closing split retains unsaved tabs and models','nested relative link origin','per-pane conflict resolution','narrow layout and save','light/dark screenshots'],nativeDesktop:'not tested'},null,2));
// A closed tab releases its editor state. The reopened note has no undo history.
await openRight('a.md','Right note'); await pane('notes/b.md').locator('.cm-content').waitFor();
const reopened=await text('notes/b.md');
assert.match(reopened,/Close guard\./);
await focus('notes/b.md'); await page.keyboard.press('Control+z');
assert.equal(await text('notes/b.md'),reopened,'Closing the tab releases only its editor state');
console.log(JSON.stringify({passed:['independent Writer/IDE/Reading modes','dirty close cancellation and editor state release','independent edits and saves','per-pane selections','focus existing duplicate target','closing split retains unsaved tabs','nested relative link origin','per-pane conflict resolution','narrow layout and save','light/dark screenshots'],nativeDesktop:'not tested'},null,2));
}, { timeout: 15000 });
+16 -14
View File
@@ -59,20 +59,20 @@ await runSmoke("layout/workbench", async ({ page }) => {
await page.getByRole("textbox", { name: "Find a file" }).fill(name);
await page.getByRole("dialog").getByRole("button").filter({ hasText: name }).first().click();
await mode("Editor layout", "IDE");
await page.locator(".monaco-editor textarea").waitFor();
await page.locator(".source-editor .cm-content").waitFor();
}
async function contents() {
return page.evaluate(async () => {
const { monaco } = await import("/src/lib/editor/monacoEnv.ts");
return monaco.editor.getEditors().find(editor => editor.getDomNode()?.isConnected)?.getValue();
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
return EditorView.findFromDOM(document.querySelector(".source-editor .cm-content"))?.state.doc.toString();
});
}
async function waitForText(text) {
await page.evaluate(async () => { window.__MONACO__ = (await import("/src/lib/editor/monacoEnv.ts")).monaco; });
await page.waitForFunction(expected => window.__MONACO__.editor.getEditors().some(editor => editor.getDomNode()?.isConnected && editor.getValue() === expected), text);
await page.evaluate(async () => { window.__EditorView = (await import("/node_modules/@codemirror/view/dist/index.js")).EditorView; });
await page.waitForFunction(expected => window.__EditorView.findFromDOM(document.querySelector(".source-editor .cm-content"))?.state.doc.toString() === expected, text);
}
async function focusEditor() {
await page.locator(".monaco-host .view-lines").click({position:{x:120,y:12}});
await page.locator(".source-editor .cm-content").click({position:{x:120,y:12}});
}
await page.goto(smokeUrl);
@@ -88,7 +88,7 @@ await runSmoke("layout/workbench", async ({ page }) => {
await page.getByRole("tab", { name: /welcome\.md/ }).click();
await focusEditor();
await page.keyboard.press("Control+z");
await page.waitForFunction(expected => window.__MONACO__.editor.getEditors().some(editor => editor.getDomNode()?.isConnected && editor.getValue() !== expected), original + "Added in source.");
await page.waitForFunction(expected => window.__EditorView.findFromDOM(document.querySelector(".source-editor .cm-content"))?.state.doc.toString() !== expected, original + "Added in source.");
await page.keyboard.press("Control+y");
await waitForText(original + "Added in source.");
await page.keyboard.press("Control+s");
@@ -96,7 +96,7 @@ await runSmoke("layout/workbench", async ({ page }) => {
await mode("Document view", "Split");
await page.locator(".md-page h1").first().waitFor();
assert.ok(await page.locator(".monaco-host").isVisible());
assert.ok(await page.locator(".source-editor").isVisible());
await page.evaluate(() => {
window.__TEST__.files.set("notes/welcome.md", "# Agent update\n");
window.__TEST__.emit("workspace-event", { root: window.__TEST__.root, kind: "modify", paths: ["notes/welcome.md"] });
@@ -132,7 +132,7 @@ await runSmoke("layout/workbench", async ({ page }) => {
await page.getByLabel("New file path relative to the workspace").fill("notes/new-note.md");
await page.getByRole("button", { name: "Continue", exact: true }).click();
await page.getByRole("tab", { name: "new-note.md", exact: true }).waitFor();
// A new note starts in its filename field, which keeps its own keys (src/lib/editor/LiveWriter.svelte:381, src/lib/editor/noteTitle.ts:80).
// A new note starts in its filename field, which keeps its own keys (src/lib/editor/DocumentEditor.svelte:386-392, src/lib/editor/noteTitle.ts:80).
await page.getByRole("textbox", { name: "Note filename", exact: true }).waitFor();
await page.screenshot({ path: path.join(output, "core-rebuild.png") });
await page.keyboard.press("Escape");
@@ -156,7 +156,7 @@ await runSmoke("layout/workbench", async ({ page }) => {
await read.click();
assert.equal(await read.getAttribute("aria-pressed"), "true");
await page.locator(".reading h1:not(.document-title)").waitFor();
assert.equal(await page.locator(".monaco-host").isVisible(), false);
assert.equal(await page.locator(".source-editor").isVisible(), false);
assert.equal(await page.locator(".reading h1:not(.document-title)").innerText(), "Project field notes");
assert.equal(await page.locator(".reading ol > li").count(), 3);
assert.equal(await page.locator(".reading ol ul > li").count(), 2);
@@ -178,8 +178,8 @@ await runSmoke("layout/workbench", async ({ page }) => {
assert.ok(await page.locator(".md-page").evaluate(element => element.scrollWidth <= element.clientWidth + 1));
await mode("Document view", "Split");
await page.waitForFunction(() => {
const host = document.querySelector(".monaco-host");
const rendered = host?.querySelector(".monaco-editor");
const host = document.querySelector(".source-editor");
const rendered = host?.querySelector(".cm-editor");
return rendered && Math.abs(host.clientWidth - rendered.clientWidth) < 2;
});
assert.equal(await page.locator(".body.split").evaluate(element => getComputedStyle(element).flexDirection), "column");
@@ -191,7 +191,8 @@ await runSmoke("layout/workbench", async ({ page }) => {
await page.screenshot({ path: path.join(output, "reader-split-wide.png") });
await mode("Document view", "Edit");
assert.equal(await contents(), showcase);
// The editor stores one line break character. The saved file keeps its own line breaks.
assert.equal(await contents(), showcase.replace(/\r\n/g, "\n"));
assert.equal(await page.evaluate(() => window.__TEST__.files.get("reader-showcase.md")), showcase);
await documentView.hover();
await read.focus();
@@ -235,7 +236,8 @@ await runSmoke("layout/workbench", async ({ page }) => {
await waitForText(writingSource);
await mode("Editor layout", "Writer");
await writer.waitFor();
await paragraph.click();
// Write keeps the caret of the IDE undo, so the paragraph can show its source.
await page.locator(".live-writer .cm-line").filter({ hasText: /A (\*\*)?formatted(\*\*)? paragraph\./ }).click();
await page.keyboard.press("End");
await page.keyboard.press("Enter");
await page.keyboard.press("Enter");
+10 -10
View File
@@ -30,7 +30,7 @@ await runSmoke("links/fileDragLinks", async ({ page }) => {
await page.mouse.up();
}
const writerSource = () => page.evaluate(() => window.dragWriter.state.doc.toString());
const ideSource = () => page.evaluate(() => window.dragMonaco.getValue());
const ideSource = () => page.evaluate(() => window.dragSource.state.doc.toString());
await page.goto(smokeUrl);
await row("notes").click();
@@ -60,21 +60,21 @@ await runSmoke("links/fileDragLinks", async ({ page }) => {
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(".monaco-editor textarea").waitFor();
await page.locator(".source-editor .cm-content").waitFor();
await page.evaluate(async () => {
const { monaco } = await import("/src/lib/editor/monacoEnv.ts");
window.dragMonaco = monaco.editor.getEditors().find(editor => editor.getDomNode()?.isConnected);
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", ".monaco-editor .view-lines");
await page.waitForFunction(() => window.dragMonaco.getValue().includes(".pdf)"));
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.dragMonaco.focus());
assert.equal(await page.evaluate(() => window.dragMonaco.hasTextFocus()), true);
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.dragMonaco.getValue() === expected, originalIde, { timeout: 3000 });
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", ".monaco-editor .view-lines");
await drag("images/diagram (#1).svg", ".source-editor .cm-content");
assert.ok((await ideSource()).includes("![](../images/diagram%20%28%231%29.svg)"));
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");
+3 -3
View File
@@ -108,10 +108,10 @@ await runSmoke("links/linkMenus", async ({ page }) => {
await page.getByRole('group', { name: 'Document view', exact: true }).hover();
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('.monaco-editor').waitFor();
await page.evaluate(async () => { const {monaco}=await import('/src/lib/editor/monacoEnv.ts'); const editor=monaco.editor.getEditors()[0]; const model=editor.getModel(); const pos=model.getPositionAt(model.getValue().indexOf('Web label')+2); editor.setPosition(pos); editor.focus(); });
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.toString().indexOf('Web label')+2}}); view.focus(); });
await page.keyboard.press('Shift+F10'); await item('Edit link').click();
assert.equal(await page.evaluate(async () => { const {monaco}=await import('/src/lib/editor/monacoEnv.ts'); const editor=monaco.editor.getEditors()[0]; return editor.getModel().getValueInRange(editor.getSelection()); }), 'https://example.com/path');
assert.equal(await page.evaluate(async () => { const {EditorView}=await import('/node_modules/@codemirror/view/dist/index.js'); const {state}=EditorView.findFromDOM(document.querySelector('.source-editor .cm-content')); return state.sliceDoc(state.selection.main.from,state.selection.main.to); }), 'https://example.com/path');
await page.screenshot({ path: `${output}/ide-edit-url-${theme}.png` });
await page.getByRole('group', { name:'Editor layout',exact:true }).hover(); await page.getByRole('button',{name:'Writer',exact:true}).click();
await page.locator('.cm-content').getByText('Selected reading text.', {exact:true}).click();
+2 -2
View File
@@ -112,13 +112,13 @@ await runSmoke("links/sectionLinks", async ({ page }) => {
await page.screenshot({ path:`${output}/split-${theme}-${width}.png` });
await choose('Document view', 'edit');
await choose('Editor layout', 'Ide');
await page.locator('.monaco-editor').waitFor();
await page.locator('.source-editor .cm-content').waitFor();
await choose('Document view', 'read');
await page.locator('.md-page').evaluate(node => { node.scrollTop = 0; });
await readerJump('Linux setup', 'Linux (Intel/AMD 64-bit)');
await choose('Document view', 'edit');
await page.waitForFunction(() => {
const node = document.querySelector('.monaco-editor .view-lines');
const node = document.querySelector('.source-editor .cm-content');
return node?.textContent.includes('Linux');
});
await page.screenshot({ path:`${output}/ide-${theme}-${width}.png` });
@@ -66,8 +66,8 @@ await runSmoke('settings/displayLanguage', async ({ browser }) => {
}), `${language}: Delete selected table cell keyboard action`);
await settings.screenshot({ path: path.join(output, `${language}-general.png`) });
await main.locator('[data-tree-rel="theme-0.py"]').click();
await main.locator('.monaco-editor textarea').waitFor();
await main.locator('.view-lines').first().click({ button: 'right' });
await main.locator('.source-editor .cm-content').waitFor();
await main.locator('.source-editor .cm-content').click({ button: 'right' });
await main.locator('.rs-menu').waitFor();
const copyLabels = { fr: 'Copier', ja: 'コピー', 'zh-CN': '复制', en: 'Copy' };
await main.locator('.rs-menu .action-label').filter({ hasText: new RegExp('^' + copyLabels[language] + '$') }).waitFor();
+6 -5
View File
@@ -43,8 +43,9 @@ await runSmoke("settings/general", async ({ browser }) => {
}
async function edit(value) {
await page.evaluate(async text => {
const { monaco } = await import("/src/lib/editor/monacoEnv.ts");
monaco.editor.getEditors().find(editor => editor.getDomNode()?.isConnected).setValue(text);
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
const view = EditorView.findFromDOM(document.querySelector(".source-editor .cm-content"));
view.dispatch({ changes: { from: 0, to: view.state.doc.length, insert: text } });
}, value);
}
const writes = () => page.evaluate(() => window.__TEST__.state.writes.length);
@@ -77,7 +78,7 @@ await runSmoke("settings/general", async ({ browser }) => {
await page.keyboard.press("Control+p");
await page.getByRole("textbox", { name: "Find a file" }).fill("note.txt");
await page.getByRole("dialog").getByRole("button").filter({ hasText: "note.txt" }).first().click();
await page.locator(".monaco-editor textarea").waitFor();
await page.locator(".source-editor .cm-content").waitFor();
await page.clock.pauseAt(new Date(await page.evaluate(() => Date.now()) + 1000));
await showSettings();
await changeSeconds(3);
@@ -99,11 +100,11 @@ await runSmoke("settings/general", async ({ browser }) => {
assert.equal(await writes(), before + 1);
await page.keyboard.press("Control+s");
await page.waitForFunction(count => window.__TEST__.state.writes.length === count, before + 2);
await page.locator(".monaco-editor textarea").focus();
await page.locator(".source-editor .cm-content").focus();
await showSettings(true);
await settings.waitFor();
await closeSettings();
await page.locator(".monaco-editor textarea").focus();
await page.locator(".source-editor .cm-content").focus();
await page.keyboard.press("F1");
await page.getByRole("dialog", { name: "Help and about", exact: true }).waitFor();
await page.keyboard.press("Escape");
+1 -1
View File
@@ -21,7 +21,7 @@ await runSmoke("tables/drag", async ({ page }) => {
await page.getByRole("textbox", { name: "Find a file" }).fill(name);
await page.getByRole("dialog").getByRole("button").filter({ hasText: name }).first().click();
await page.getByRole("group", { name: "Editor layout" }).locator("button.current").press("Home");
await page.locator(".monaco-editor textarea").waitFor();
await page.locator(".source-editor .cm-content").waitFor();
}
const table = page.locator('.live-writer table');
const rows = () => table.locator('tbody tr td:first-child').allTextContents();
+1 -1
View File
@@ -22,7 +22,7 @@ await runSmoke("tables/formulas", async ({ page }) => {
await page.getByRole("dialog").getByRole("button").filter({ hasText: name }).first().click();
await page.locator('.live-writer').waitFor();
await page.keyboard.press('Control+e');
await page.locator(".monaco-editor textarea").waitFor();
await page.locator(".source-editor .cm-content").waitFor();
}
const table = page.locator('.live-writer table');
const cell = (r, c) => table.locator('tr').nth(r).locator('th, td').nth(c);
+1 -1
View File
@@ -63,7 +63,7 @@ await runSmoke("tabs/menus", async ({ page }) => {
await page.locator(".cm-editor").waitFor();
await show("d.md");
await item("Source mode").click();
await page.locator(".monaco-editor").waitFor();
await page.locator(".source-editor .cm-content").waitFor();
await show("d.md");
await item("Writing mode").click();
await page.locator(".cm-editor").waitFor();
+6 -13
View File
@@ -17,18 +17,11 @@ await runSmoke("tabs/scroll", async ({ page }) => {
}
async function roundTrip(selector, label) {
const scroller = page.locator(selector);
const position = async (top) => label === 'IDE'
? page.evaluate(async top => {
const { monaco } = await import('/src/lib/editor/monacoEnv.ts');
const editor = monaco.editor.getEditors().find(view => view.getDomNode()?.isConnected);
if (top !== undefined) editor.setScrollTop(top, 1);
return editor.getScrollTop();
}, top)
: scroller.evaluate((el, top) => {
if (top !== undefined) el.scrollTop = top;
return el.scrollTop;
}, top);
// The Writing layout restores a line-anchored CodeMirror scrollSnapshot (src/lib/editor/LiveWriter.svelte:330-333).
const position = async (top) => scroller.evaluate((el, top) => {
if (top !== undefined) el.scrollTop = top;
return el.scrollTop;
}, top);
// The Writing layout restores a line-anchored CodeMirror scrollSnapshot (src/lib/editor/DocumentEditor.svelte:304-305).
// Re-estimated heights of the lines above can move scrollTop, so compare the top visible line and its offset.
const visibleTop = () => label === 'Writing'
? scroller.evaluate(async el => {
@@ -86,5 +79,5 @@ await runSmoke("tabs/scroll", async ({ page }) => {
await page.getByRole('tab', { name: 'scroll-b.md', exact: true }).click();
await mode('Editor layout', 'IDE');
await page.getByRole('tab', { name: 'scroll-a.md', exact: true }).click();
await roundTrip('.monaco-scrollable-element', 'IDE');
await roundTrip('.source-editor .cm-scroller', 'IDE');
});
+6 -9
View File
@@ -44,9 +44,9 @@ await runSmoke("tree/newFiles", async ({ page }) => {
}
async function modelDetails() {
return page.evaluate(async () => {
const { monaco } = await import("/src/lib/editor/monacoEnv.ts");
const editor = monaco.editor.getEditors().find(editor => editor.getDomNode()?.isConnected);
return editor && { language: editor.getModel().getLanguageId(), value: editor.getValue(), fontSize: editor.getOption(monaco.editor.EditorOption.fontSize) };
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
const view = EditorView.findFromDOM(document.querySelector(".source-editor .cm-content"));
return view && { language: view.contentDOM.dataset.language, value: view.state.doc.toString(), fontSize: parseFloat(getComputedStyle(view.contentDOM).fontSize) };
});
}
@@ -67,17 +67,14 @@ await runSmoke("tree/newFiles", async ({ page }) => {
await row("notes/hello_world.py").waitFor();
assert.equal(await page.evaluate(() => window.__TEST__.files.has("notes/hello_world.py.md")), false);
await row("hello.txt").dblclick();
await page.waitForFunction(() => !!document.querySelector(".monaco-editor .view-line"));
await page.waitForFunction(() => !!document.querySelector(".source-editor .cm-line"));
await row("hello.txt").click({ button: "right" });
await page.getByRole("menuitem", { name: "Rename", exact: true }).click();
assert.equal(await row("hello.txt").locator("input.rename").inputValue(), "hello.txt");
await row("hello.txt").locator("input.rename").fill("hello.py");
await page.keyboard.press("Enter");
await row("hello.py").waitFor();
await page.waitForFunction(async () => {
const { monaco } = await import("/src/lib/editor/monacoEnv.ts");
return monaco.editor.getEditors().some(editor => editor.getDomNode()?.isConnected && editor.getModel()?.getLanguageId() === "python");
});
await page.waitForFunction(() => document.querySelector(".source-editor .cm-content")?.getAttribute("data-language") === "python");
const code = await modelDetails();
assert.equal(code.value, "print('hello')\n");
assert.equal(code.fontSize, 13);
@@ -102,7 +99,7 @@ await runSmoke("tree/newFiles", async ({ page }) => {
return !event.defaultPrevented;
});
// Writer combines spelling suggestions with the Markdown actions (docs/design-decisions.md UI-027;
// src/lib/editor/LiveWriter.svelte:255-262 prevents the native menu and passes the spelling offset).
// the contextmenu handler of src/lib/editor/DocumentEditor.svelte prevents the native menu and passes the spelling offset).
assert.equal(nativeAllowed, false, "Plain text opens the shared Markdown menu instead of the native one");
const textMenu = page.getByRole("menu", { name: "Markdown text actions", exact: true });
await textMenu.getByRole("menuitem", { name: "Misspelled", exact: true }).waitFor();
@@ -47,10 +47,11 @@ await runSmoke("workspace/openAndCreate", async ({ page }) => {
await page.keyboard.press("Control+p");
await page.getByRole("textbox", { name: "Find a file" }).fill("note.txt");
await page.getByRole("dialog").getByRole("button").filter({ hasText: "note.txt" }).first().click();
await page.locator(".monaco-editor textarea").waitFor();
await page.locator(".source-editor .cm-content").waitFor();
await page.evaluate(async () => {
window.__MONACO__ = (await import("/src/lib/editor/monacoEnv.ts")).monaco;
window.__MONACO__.editor.getEditors().find(e => e.getDomNode()?.isConnected).setValue("My pending edit");
window.__EditorView = (await import("/node_modules/@codemirror/view/dist/index.js")).EditorView;
const view = window.__EditorView.findFromDOM(document.querySelector(".source-editor .cm-content"));
view.dispatch({ changes: { from: 0, to: view.state.doc.length, insert: "My pending edit" } });
});
const trigger = page.getByRole("button", { name: "Open folder", exact: true });
const menu = page.getByRole("dialog", { name: "Workspaces", exact: true });
@@ -97,7 +98,7 @@ await runSmoke("workspace/openAndCreate", async ({ page }) => {
assert.deepEqual(await page.evaluate(() => window.__TEST__.windows), ["D:\\Writing\\Notes", "D:\\Other", "D:\\Projects\\Fresh notes"]);
assert.equal(await page.evaluate(() => window.__TEST__.calls.filter(c => c.command === "workspace_open").length), opened);
assert.equal(await page.evaluate(() => window.__TEST__.calls.filter(c => c.command === "plugin:dialog|message").length), 0);
assert.equal(await page.evaluate(() => window.__MONACO__.editor.getEditors().find(e => e.getDomNode()?.isConnected)?.getValue()), "My pending edit");
assert.equal(await page.evaluate(() => window.__EditorView.findFromDOM(document.querySelector(".source-editor .cm-content"))?.state.doc.toString()), "My pending edit");
assert(await page.getByRole("tab", { name: /note\.txt/ }).isVisible());
await trigger.click();
await page.keyboard.press("End");
+1 -7
View File
@@ -1,7 +1,7 @@
import test from "node:test";
import assert from "node:assert/strict";
import { SearchQuery } from "@codemirror/search";
import { documentMatches, replacementText } from "../../../src/lib/editor/findTarget.ts";
import { documentMatches } from "../../../src/lib/editor/findTarget.ts";
test("document search uses Writer word matching and normalized CRLF positions", () => {
const query = new SearchQuery({ search: "Alpha", wholeWord: true, caseSensitive: true });
@@ -11,12 +11,6 @@ test("document search uses Writer word matching and normalized CRLF positions",
assert.equal(state.doc.lineAt(matches[1].from).from, 15);
});
test("replacement keeps regex context, capture groups, dollars, and line breaks", () => {
const query = new SearchQuery({ search: "(?<=G)(amma)", regexp: true, replace: "$1-$12-$&-$$\\n" });
assert.equal(replacementText("Gamma", 1, query), "amma-amma2-amma-$\n");
assert.equal(replacementText("Alpha", 0, new SearchQuery({ search: "Alpha", replace: "$1\\t" })), "$1\t");
});
test("empty and invalid queries do not produce matches", () => {
assert.deepEqual(documentMatches("Alpha", new SearchQuery({ search: "" })).matches, []);
assert.deepEqual(documentMatches("Alpha", new SearchQuery({ search: "[", regexp: true })).matches, []);
+90
View File
@@ -0,0 +1,90 @@
import assert from "node:assert/strict";
import test from "node:test";
import { EditorState } from "@codemirror/state";
import { indentUnit } from "@codemirror/language";
import { markdown, markdownLanguage } from "@codemirror/lang-markdown";
import { noteFormats } from "../../../src/lib/editor/noteFormats.ts";
import { indentListItems, listLabels, orderedLabel, outdentListItems } from "../../../src/lib/editor/markdownLists.ts";
const extensions = [markdown({ base: markdownLanguage, extensions: [noteFormats] }), indentUnit.of(" ")];
/** A document with `|` at the caret, or two `|` around a selection. */
function editor(marked: string) {
const anchor = marked.indexOf("|"), head = marked.indexOf("|", anchor + 1);
const doc = marked.replaceAll("|", "");
return EditorState.create({ doc, selection: { anchor, head: head < 0 ? anchor : head - 1 }, extensions });
}
function run(move: typeof indentListItems, marked: string) {
const state = editor(marked), specs = move(state);
if (!specs) return null;
const next = state.update(...specs).state;
const { from, to } = next.selection.main;
const doc = next.doc.toString();
return from === to ? doc.slice(0, from) + "|" + doc.slice(from) : doc.slice(0, from) + "|" + doc.slice(from, to) + "|" + doc.slice(to);
}
test("tab makes a nested list and renumbers the items after it", () => {
assert.equal(run(indentListItems, "1. Topic\n2. B|\n3. A"), "1. Topic\n 1. B|\n2. A");
});
test("tab on an empty item keeps the caret after its marker", () => {
assert.equal(run(indentListItems, "1. Topic\n2.|\n3. A"), "1. Topic\n 1.|\n2. A");
assert.equal(run(indentListItems, "1. Topic\n2. |\n3. A"), "1. Topic\n 1. |\n2. A");
});
test("tab adds the item to the nested list of the previous item", () => {
assert.equal(run(indentListItems, "1. A\n 1. x\n2. B|\n3. C"), "1. A\n 1. x\n 2. B|\n2. C");
});
test("tab moves the children of an item with it", () => {
assert.equal(run(indentListItems, "1. A\n2. B|\n 1. b\n3. C"), "1. A\n 1. B|\n 1. b\n2. C");
});
test("tab nests each selected item under the first unselected item", () => {
assert.equal(run(indentListItems, "1. A\n|2. B\n3. C|\n4. D"), "1. A\n| 1. B\n 2. C|\n2. D");
});
test("tab nests bullet items and keeps their marker", () => {
assert.equal(run(indentListItems, "- a\n- b|"), "- a\n - b|");
assert.equal(run(indentListItems, "- [ ] a\n- [x] b|"), "- [ ] a\n - [x] b|");
});
test("tab keeps the first item in place and ignores text outside lists", () => {
assert.deepEqual(indentListItems(editor("1. A|\n2. B")), []);
assert.equal(indentListItems(editor("Plain| text")), null);
assert.equal(indentListItems(editor("1. A\n\n ```\n co|de\n ```")), null);
});
test("shift+tab moves a nested item up and makes the later items its children", () => {
assert.equal(run(outdentListItems, "1. A\n 1. x\n 2. y|\n 3. z\n2. B"), "1. A\n 1. x\n2. y|\n 1. z\n3. B");
});
test("shift+tab gives the item the marker style of the outer list", () => {
assert.equal(run(outdentListItems, "1. A\n - x|\n2. B"), "1. A\n2. x|\n3. B");
assert.equal(run(outdentListItems, "- A\n 1. x|\n- B"), "- A\n- x|\n- B");
});
test("shift+tab keeps a top-level item in place", () => {
assert.deepEqual(outdentListItems(editor("1. A|\n2. B")), []);
assert.equal(outdentListItems(editor("Plain| text")), null);
});
test("ordered labels use numbers, letters, and Roman numerals by level", () => {
assert.equal(orderedLabel(1, 3), "3");
assert.equal(orderedLabel(2, 1), "a");
assert.equal(orderedLabel(2, 27), "aa");
assert.equal(orderedLabel(3, 4), "iv");
assert.equal(orderedLabel(4, 2), "2");
assert.equal(orderedLabel(2, 0), "0");
});
test("nested ordered markers get labels and the first level keeps its source", () => {
const state = editor("1. A\n 1. x\n 1. y\n 1. z\n2. B|");
assert.deepEqual(listLabels(state).map(label => [state.sliceDoc(label.from, label.to), label.label]), [["1.", "a."], ["1.", "b."], ["1.", "i."]]);
});
test("an empty nested marker gets its label before the item has text", () => {
const state = editor("1. Topic\n 1.\n2. A|");
assert.deepEqual(listLabels(state).map(label => label.label), ["a."]);
});
+5 -10
View File
@@ -1,7 +1,6 @@
import assert from "node:assert/strict";
import test from "node:test";
import { detectChrome, extensionOf, treeFileParts } from "../../../src/lib/workspace/chrome.ts";
import { monacoChrome } from "../../../src/lib/editor/monacoChrome.ts";
import { chromeLayout, detectChrome, extensionOf, treeFileParts } from "../../../src/lib/workspace/chrome.ts";
test("markdown files open in writing chrome", () => {
assert.equal(detectChrome("notes/inbox.md"), "Writing");
@@ -14,16 +13,12 @@ test("scripts open in ide chrome", () => {
assert.equal(detectChrome("Makefile"), "Ide");
});
test("writing chrome wraps and hides line numbers", () => {
assert.equal(monacoChrome("Writing").wordWrap, "on");
assert.equal(monacoChrome("Writing").lineNumbers, "off");
assert.equal(monacoChrome("Writing").minimap.enabled, false);
test("writing chrome wraps and hides the code gutters", () => {
assert.deepEqual(chromeLayout("Writing"), { wrap: true, gutters: false, activeLine: false });
});
test("ide chrome shows line numbers and no wrap", () => {
assert.equal(monacoChrome("Ide").wordWrap, "off");
assert.equal(monacoChrome("Ide").lineNumbers, "on");
assert.equal(monacoChrome("Ide").minimap.enabled, true);
test("ide chrome shows the code gutters and does not wrap", () => {
assert.deepEqual(chromeLayout("Ide"), { wrap: false, gutters: true, activeLine: true });
});
test("extensionOf reads the last suffix", () => {