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