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:
@@ -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();
|
||||
|
||||
@@ -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 });
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user