RuneStone 1.0.0
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
// Checklist entry: keyboard marker editing, checkbox toggles, and pasted HTML tables in both themes and a narrow layout.
|
||||
import assert from "node:assert/strict";
|
||||
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("editor/checklistEntry", async ({ page }) => {
|
||||
await mockTauri(page, {
|
||||
commands: test => ({
|
||||
...test.workspace({
|
||||
root: "C:\\smoke-workspace",
|
||||
files: {
|
||||
"notes/welcome.md": "---\ntitle: Welcome\n---\n\n# Working notes\n\nFirst paragraph.\n\n- [ ] A task\n\n[[second]]\n",
|
||||
"notes/second.md": "# Second note\n",
|
||||
"src/hello.py": "print('hello')\n",
|
||||
},
|
||||
}),
|
||||
spelling_menu_install: () => null,
|
||||
}),
|
||||
});
|
||||
const output = await outputDir("editor/checklistEntry");
|
||||
await page.goto(smokeUrl);
|
||||
await page.getByText('smoke-workspace', { exact: true }).waitFor();
|
||||
await page.keyboard.press('Control+p');
|
||||
await page.getByRole('textbox', { name: 'Find a file' }).fill('welcome.md');
|
||||
await page.getByRole('dialog').getByRole('button').filter({ hasText: 'welcome.md' }).first().click();
|
||||
await page.getByRole('textbox', { name: 'Writing 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 source = '# Clipboard and tasks\n\n- [ ] CCNA lab\n- [x] CCNA course\n\nPaste here.\n';
|
||||
const reset = async () => page.evaluate(source => {
|
||||
window.__CM__.dispatch({ changes: { from: 0, to: window.__CM__.state.doc.length, insert: source }, selection: { anchor: source.indexOf('CCNA lab') } });
|
||||
window.__CM__.focus();
|
||||
}, source);
|
||||
const count = () => page.locator('.writer-checkbox').count();
|
||||
const clipboard = '<html><body><!--StartFragment--><table><thead><tr><th>Ticker</th><th>Name</th></tr></thead><tbody><tr><td>ADBE.US</td><td>Adobe</td></tr><tr><td>ADSK.US</td><td>Autodesk</td></tr></tbody></table><!--EndFragment--></body></html>';
|
||||
for (const mode of ['dark', 'light']) {
|
||||
await page.evaluate(async mode => (await import('/src/lib/theme/appearance.ts')).saveAppearance({ theme: 'default', mode }), mode);
|
||||
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: width === 600 ? 760 : 1000 });
|
||||
await reset();
|
||||
assert.equal(await count(), 2, 'Caret at task text keeps both checkboxes');
|
||||
await page.screenshot({ path: `${output}/${mode}-${width}-task-text.png` });
|
||||
await page.keyboard.press('ArrowLeft');
|
||||
assert.equal(await count(), 1, 'ArrowLeft from text reveals the marker');
|
||||
await page.screenshot({ path: `${output}/${mode}-${width}-task-marker.png` });
|
||||
await page.keyboard.press('Home');
|
||||
assert.equal(await count(), 1, 'Home keeps the marker editable');
|
||||
await page.keyboard.press('ArrowRight');
|
||||
await page.keyboard.press('ArrowRight');
|
||||
await page.keyboard.press('ArrowRight');
|
||||
await page.keyboard.press('Delete');
|
||||
await page.keyboard.type('x');
|
||||
assert.match(await page.evaluate(() => window.__CM__.state.sliceDoc()), /- \[x\] CCNA lab/);
|
||||
await page.keyboard.press('Home');
|
||||
for (let i = 0; i < 6; i++) await page.keyboard.press('ArrowRight');
|
||||
assert.equal(await count(), 2, 'Leaving the marker restores the checkbox');
|
||||
await page.keyboard.type('New ');
|
||||
assert.equal(await count(), 2, 'Typing task text keeps the checkbox');
|
||||
await page.locator('.writer-checkbox').first().click();
|
||||
assert.match(await page.evaluate(() => window.__CM__.state.sliceDoc()), /- \[ \] New CCNA lab/);
|
||||
await page.evaluate(() => {
|
||||
const view = window.__CM__;
|
||||
view.dispatch({ selection: { anchor: view.state.sliceDoc().indexOf('Paste here.') } }); view.focus();
|
||||
});
|
||||
await page.getByRole('textbox', { name: 'Writing editor', exact: true }).evaluate((node, html) => {
|
||||
const data = new DataTransfer(); data.setData('text/html', html); data.setData('text/plain', 'Ticker\tName\nADBE.US\tAdobe\nADSK.US\tAutodesk');
|
||||
node.dispatchEvent(new ClipboardEvent('paste', { clipboardData: data, bubbles: true, cancelable: true }));
|
||||
}, clipboard);
|
||||
await page.locator('.live-writer table').waitFor();
|
||||
const pasted = await page.evaluate(() => window.__CM__.state.sliceDoc());
|
||||
assert.doesNotMatch(pasted, /Fragment|<!--|-->/);
|
||||
assert.match(pasted, /\| Ticker \| Name \|/);
|
||||
assert.equal(await page.locator('.live-writer table tr').count(), 3);
|
||||
await page.screenshot({ path: `${output}/${mode}-${width}-table-paste.png` });
|
||||
if (width === 600) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,83 @@
|
||||
// Code blocks: editing fenced and indented code in the Writer, with undo, cursor movement, preview, and save.
|
||||
import assert from "node:assert/strict";
|
||||
import { mockTauri, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("editor/codeBlocks", async ({ page }) => {
|
||||
await mockTauri(page, {
|
||||
commands: test => {
|
||||
const workspace = test.workspace({
|
||||
root: "C:\\smoke-workspace",
|
||||
files: {
|
||||
"notes/welcome.md": "---\ntitle: Welcome\n---\n\n# Working notes\n\nFirst paragraph.\n\n- [ ] A task\n\n[[second]]\n",
|
||||
"notes/second.md": "# Second note\n",
|
||||
"src/hello.py": "print('hello')\n",
|
||||
},
|
||||
writeEvents: true,
|
||||
});
|
||||
test.files = workspace.files;
|
||||
return {
|
||||
...workspace,
|
||||
// Saves send the last saved text. Reject a save when the file changed, as the backend does.
|
||||
workspace_write: args => {
|
||||
if (args.expected !== undefined && workspace.files.get(args.rel) !== args.expected) throw new Error("Save blocked: file changed on disk");
|
||||
return workspace.workspace_write(args);
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
await page.goto(smokeUrl);
|
||||
await page.getByText("smoke-workspace", { exact: true }).waitFor();
|
||||
await page.keyboard.press("Control+p");
|
||||
await page.getByRole("textbox", { name: "Find a file" }).fill("welcome.md");
|
||||
await page.getByRole("dialog").getByRole("button").filter({ hasText: "welcome.md" }).first().click();
|
||||
await page.getByRole("textbox", { name: "Writing 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 contents = () => page.evaluate(() => window.__CM__.state.sliceDoc());
|
||||
const cursor = () => page.evaluate(() => window.__CM__.state.selection.main.head);
|
||||
async function select(anchor, head = anchor) {
|
||||
await page.evaluate(({ anchor, head }) => {
|
||||
window.__CM__.dispatch({ selection: { anchor, head }, scrollIntoView: true });
|
||||
window.__CM__.focus();
|
||||
}, { anchor, head });
|
||||
}
|
||||
for (const block of ["```js\nconst value = 123;\nsecond line\n```", "~~~text\nconst value = 123;\nsecond line\n~~~", " const value = 123;\n second line"]) {
|
||||
const original = `Above.\n\n${block}\n\nBelow.\n`;
|
||||
await page.evaluate(value => {
|
||||
window.__CM__.dispatch({ changes: { from: 0, to: window.__CM__.state.doc.length, insert: value }, selection: { anchor: 0 } });
|
||||
}, original);
|
||||
await page.locator(".writer-code-line").first().click();
|
||||
await page.locator(".writer-code-source").first().waitFor();
|
||||
const position = original.indexOf("123") + 1;
|
||||
await select(position);
|
||||
await page.keyboard.press("Backspace");
|
||||
assert.equal(await contents(), original.slice(0, position - 1) + original.slice(position));
|
||||
await page.keyboard.press("Control+z");
|
||||
assert.equal(await contents(), original);
|
||||
await select(position);
|
||||
await page.keyboard.press("Delete");
|
||||
assert.equal(await contents(), original.slice(0, position) + original.slice(position + 1));
|
||||
await page.keyboard.press("Control+z");
|
||||
assert.equal(await contents(), original);
|
||||
await select(position);
|
||||
await page.keyboard.press("ArrowRight");
|
||||
assert.equal(await cursor(), position + 1);
|
||||
await page.keyboard.press("ArrowLeft");
|
||||
assert.equal(await cursor(), position);
|
||||
await page.keyboard.type("X");
|
||||
assert.equal(await contents(), original.slice(0, position) + "X" + original.slice(position));
|
||||
await page.keyboard.press("Control+z");
|
||||
assert.equal(await contents(), original);
|
||||
await select(position - 1, position + 2);
|
||||
await page.keyboard.press("Backspace");
|
||||
const edited = original.slice(0, position - 1) + original.slice(position + 2);
|
||||
assert.equal(await contents(), edited);
|
||||
await select(0);
|
||||
assert.ok((await page.locator(".writer-code-line").allTextContents()).join("\n").includes("const value = ;"));
|
||||
await page.keyboard.press("Control+s");
|
||||
await page.waitForFunction(value => window.__TEST__.files.get("notes/welcome.md") === value, edited);
|
||||
}
|
||||
console.log("PASS: Fenced and indented code editing, character deletion, selection deletion, cursor movement, undo, preview and save.");
|
||||
});
|
||||
@@ -0,0 +1,87 @@
|
||||
// Dividers: thematic break syntax, width, source editing, keyboard navigation, selection, undo, and save.
|
||||
import assert from "node:assert/strict";
|
||||
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("editor/dividers", async ({ page }) => {
|
||||
await mockTauri(page, {
|
||||
commands: test => {
|
||||
const workspace = test.workspace({
|
||||
root: "C:\\smoke-workspace",
|
||||
files: {
|
||||
"notes/welcome.md": "---\ntitle: Welcome\n---\n\n# Working notes\n\nFirst paragraph.\n\n- [ ] A task\n\n[[second]]\n",
|
||||
"notes/second.md": "# Second note\n",
|
||||
"src/hello.py": "print('hello')\n",
|
||||
},
|
||||
writeEvents: true,
|
||||
});
|
||||
test.files = workspace.files;
|
||||
return {
|
||||
...workspace,
|
||||
// Saves send the last saved text. Reject a save when the file changed, as the backend does.
|
||||
workspace_write: args => {
|
||||
if (args.expected !== undefined && workspace.files.get(args.rel) !== args.expected) throw new Error("Save blocked: file changed on disk");
|
||||
return workspace.workspace_write(args);
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
const output = await outputDir("editor/dividers");
|
||||
await page.goto(smokeUrl);
|
||||
await page.getByText("smoke-workspace", { exact: true }).waitFor();
|
||||
await page.keyboard.press("Control+p");
|
||||
await page.getByRole("textbox", { name: "Find a file" }).fill("welcome.md");
|
||||
await page.getByRole("dialog").getByRole("button").filter({ hasText: "welcome.md" }).first().click();
|
||||
const writer = page.getByRole("textbox", { name: "Writing editor", exact: true });
|
||||
await writer.waitFor();
|
||||
const dividers = "content\n___\ncontent\n***\n\n---\n\n* * *\n\n_ _ _\n\n- - -\n\nHeading\n---\n\n`___`\n\n```text\n___\n```\n\n ***\n\nEnd\n";
|
||||
await page.evaluate(async value => {
|
||||
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
|
||||
window.__CM__ = EditorView.findFromDOM(document.querySelector(".cm-content"));
|
||||
window.__CM__.dispatch({ changes: { from: 0, to: window.__CM__.state.doc.length, insert: value }, selection: { anchor: 0 } });
|
||||
}, dividers);
|
||||
await page.waitForFunction(() => document.querySelectorAll(".writer-divider").length === 6);
|
||||
assert.equal(await page.getByRole("separator").and(page.locator(".writer-divider")).count(), 6);
|
||||
const dividerStyle = await page.locator(".writer-divider").first().evaluate(node => ({
|
||||
width: node.getBoundingClientRect().width,
|
||||
lineWidth: node.parentElement.getBoundingClientRect().width,
|
||||
border: getComputedStyle(node, "::after").borderTopWidth,
|
||||
color: getComputedStyle(node, "::after").borderTopColor,
|
||||
}));
|
||||
assert.ok(Math.abs(dividerStyle.width - dividerStyle.lineWidth) < 2);
|
||||
assert.equal(dividerStyle.border, "1px");
|
||||
assert.notEqual(dividerStyle.color, "rgba(0, 0, 0, 0)");
|
||||
await page.setViewportSize({ width: 1100, height: 900 });
|
||||
await page.screenshot({ path: `${output}/markdown-dividers.png` });
|
||||
|
||||
await page.locator(".writer-divider").first().click();
|
||||
assert.equal(await page.locator(".writer-divider").count(), 5);
|
||||
assert.equal(await page.evaluate(() => window.__CM__.state.doc.lineAt(window.__CM__.state.selection.main.head).text), "___");
|
||||
await page.keyboard.press("End");
|
||||
await page.keyboard.press("Backspace");
|
||||
await page.keyboard.press("Control+Home");
|
||||
assert.equal(await page.locator(".writer-divider").count(), 5);
|
||||
assert.ok((await writer.textContent()).includes("__"));
|
||||
await page.keyboard.press("Control+z");
|
||||
await page.keyboard.press("Control+Home");
|
||||
assert.equal(await page.locator(".writer-divider").count(), 6);
|
||||
await page.keyboard.press("ArrowDown");
|
||||
assert.equal(await page.locator(".writer-divider").count(), 5);
|
||||
assert.equal(await page.evaluate(() => window.__CM__.state.doc.lineAt(window.__CM__.state.selection.main.head).text), "___");
|
||||
await page.keyboard.press("Control+a");
|
||||
assert.equal(await page.locator(".writer-divider").count(), 0);
|
||||
assert.equal(await page.evaluate(() => window.__CM__.state.sliceDoc()), dividers);
|
||||
await page.keyboard.press("Control+Home");
|
||||
assert.equal(await page.locator(".writer-divider").count(), 6);
|
||||
await page.keyboard.press("Control+s");
|
||||
await page.waitForFunction(value => window.__TEST__.files.get("notes/welcome.md") === value, dividers);
|
||||
|
||||
await page.evaluate(() => {
|
||||
window.__CM__.dispatch({ changes: { from: 0, to: window.__CM__.state.doc.length, insert: "Above\n\n ___\n\n> ***\n\nEnd" }, selection: { anchor: 0 } });
|
||||
});
|
||||
assert.equal(await page.locator(".writer-divider").count(), 2);
|
||||
for (const divider of await page.locator(".writer-divider").all()) {
|
||||
assert.ok(await divider.evaluate(node => node.getBoundingClientRect().right <= node.parentElement.getBoundingClientRect().right + 1));
|
||||
}
|
||||
|
||||
console.log("PASS: Divider syntax, width, source editing, keyboard navigation, selection, undo and save.");
|
||||
});
|
||||
@@ -0,0 +1,115 @@
|
||||
// Writer text menu on empty and whitespace lines: submenus, disabled actions, links, the file picker, keyboard focus, both themes, a narrow window, and the Source.
|
||||
import assert from "node:assert/strict";
|
||||
import { chooseView, mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("editor/emptyMenu", async ({ page }) => {
|
||||
await mockTauri(page, {
|
||||
commands: test => test.workspace({
|
||||
root: "C:\\smoke-workspace",
|
||||
files: {
|
||||
"notes/welcome.md": "---\ntitle: Welcome\n---\n\n# Working notes\n\nFirst paragraph.\n\n- [ ] A task\n\n[[second]]\n",
|
||||
"notes/second.md": "# Second note\n",
|
||||
"src/hello.py": "print('hello')\n",
|
||||
},
|
||||
}),
|
||||
});
|
||||
const output = await outputDir("editor/emptyMenu");
|
||||
await page.goto(smokeUrl);
|
||||
await page.getByText('smoke-workspace', { exact: true }).waitFor();
|
||||
await page.keyboard.press('Control+p');
|
||||
await page.getByRole('textbox', { name: 'Find a file' }).fill('welcome.md');
|
||||
await page.getByRole('dialog').getByRole('button').filter({ hasText: 'welcome.md' }).first().click();
|
||||
await page.getByRole('textbox', { name: 'Writing 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 menu = () => page.getByRole('menu', { name: 'Markdown text actions', exact: true });
|
||||
async function setSource(value, anchor = 0, head = anchor) {
|
||||
await page.evaluate(({value,anchor,head}) => window.__CM__.dispatch({changes:{from:0,to:window.__CM__.state.doc.length,insert:value},selection:{anchor,head}}), {value,anchor,head});
|
||||
}
|
||||
async function openKeyboard() { await page.locator('.cm-content').focus(); await page.keyboard.press('Shift+F10'); await menu().waitFor(); }
|
||||
async function source() { return page.evaluate(() => window.__CM__.state.doc.toString()); }
|
||||
for (const theme of ['light', 'dark']) {
|
||||
await page.evaluate(async mode => { const { saveAppearance } = await import('/src/lib/theme/appearance.ts'); saveAppearance({theme:'default',mode}); }, theme);
|
||||
await setSource('');
|
||||
await page.locator('.cm-line').first().click({button:'right'});
|
||||
await menu().waitFor();
|
||||
for (const label of ['Add link','Add external link Ctrl+K','Format','Paragraph','Insert','Paste Ctrl+V','Paste as plain text','Select all Ctrl+A']) assert.equal(await menu().getByRole('menuitem', {name:label,exact:true}).count(),1,label);
|
||||
assert.equal(await menu().getByRole('menuitem',{name:'Cut Ctrl+X',exact:true}).isDisabled(),true);
|
||||
assert.equal(await menu().getByRole('menuitem',{name:'Copy Ctrl+C',exact:true}).isDisabled(),true);
|
||||
await page.screenshot({path:`${output}/empty-${theme}.png`});
|
||||
await menu().getByRole('menuitem',{name:'Format',exact:true}).focus();
|
||||
await page.keyboard.press('ArrowRight');
|
||||
const format = page.getByRole('menu',{name:'Format',exact:true});
|
||||
for (const label of ['Bold Ctrl+B','Italic Ctrl+I','Strikethrough Ctrl+Shift+X','Highlight Ctrl+Shift+H','Code','Math','Comment','Clear formatting']) assert.equal(await format.getByRole('menuitem',{name:label,exact:true}).count(),1);
|
||||
await page.keyboard.press('End');
|
||||
assert.equal(await page.getByRole('menuitem',{name:'Comment',exact:true}).evaluate(el=>el===document.activeElement),true);
|
||||
await page.screenshot({path:`${output}/format-${theme}.png`});
|
||||
await page.keyboard.press('ArrowLeft');
|
||||
await page.keyboard.press('Escape');
|
||||
assert.equal(await page.locator('.cm-content').evaluate(el=>el===document.activeElement),true);
|
||||
await openKeyboard();
|
||||
await menu().getByRole('menuitem',{name:'Paragraph',exact:true}).click();
|
||||
await page.getByRole('menu',{name:'Paragraph',exact:true}).getByRole('menuitem',{name:'Heading 6',exact:true}).click();
|
||||
assert.equal(await source(),'###### ');
|
||||
await setSource(''); await openKeyboard();
|
||||
await menu().getByRole('menuitem',{name:'Insert',exact:true}).click();
|
||||
await page.screenshot({path:`${output}/insert-${theme}.png`});
|
||||
await page.getByRole('menu',{name:'Insert',exact:true}).getByRole('menuitem',{name:'Code block',exact:true}).click();
|
||||
assert.match(await source(),/^```\nCode\n```/);
|
||||
await setSource(''); await openKeyboard();
|
||||
await menu().getByRole('menuitem',{name:'Add external link Ctrl+K',exact:true}).click();
|
||||
assert.equal(await source(),'[]()');
|
||||
assert.equal(await page.evaluate(()=>window.__CM__.state.selection.main.head),1);
|
||||
assert.equal(await page.getByRole('dialog').count(),0);
|
||||
await setSource('label',0,5); await openKeyboard();
|
||||
await menu().getByRole('menuitem',{name:'Add external link Ctrl+K',exact:true}).click();
|
||||
assert.equal(await source(),'[label]()');
|
||||
assert.equal(await page.evaluate(()=>window.__CM__.state.selection.main.head),8);
|
||||
await setSource(''); await openKeyboard();
|
||||
await menu().getByRole('menuitem',{name:'Add link',exact:true}).click();
|
||||
await page.getByRole('textbox',{name:'Find a file'}).fill('second');
|
||||
await page.screenshot({path:`${output}/workspace-picker-${theme}.png`});
|
||||
await page.keyboard.press('Enter');
|
||||
await page.getByRole('dialog').waitFor({state:'detached'});
|
||||
assert.equal(await source(),'[[/notes/second.md]]');
|
||||
await setSource('Keep this text'); await openKeyboard();
|
||||
await menu().getByRole('menuitem',{name:'Add link',exact:true}).click();
|
||||
await page.getByRole('textbox',{name:'Find a file'}).waitFor();
|
||||
await page.keyboard.press('Escape');
|
||||
await page.getByRole('dialog').waitFor({state:'detached'});
|
||||
assert.equal(await source(),'Keep this text');
|
||||
await setSource('Populated paragraph\n\n');
|
||||
await page.locator('.cm-line').last().click({button:'right'});
|
||||
await menu().waitFor();
|
||||
await page.keyboard.press('Escape');
|
||||
await setSource('');
|
||||
await page.getByRole('button',{name:'Hide outline',exact:true}).click();
|
||||
await page.setViewportSize({width:560,height:420});
|
||||
await page.locator('.cm-scroller').click({button:'right',position:{x:60,y:180}});
|
||||
await menu().waitFor();
|
||||
const box = await menu().boundingBox(); assert.ok(box.x>=8 && box.y>=8 && box.x+box.width<=552 && box.y+box.height<=412);
|
||||
await page.screenshot({path:`${output}/narrow-${theme}.png`});
|
||||
await page.keyboard.press('Escape');
|
||||
await page.setViewportSize({width:1440,height:1000});
|
||||
await page.getByRole('button',{name:'Show outline',exact:true}).click();
|
||||
}
|
||||
await chooseView(page, 'Source');
|
||||
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 Ctrl+K',exact:true}).click();
|
||||
assert.equal(await page.getByRole('dialog').count(),0);
|
||||
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');
|
||||
await menu().getByRole('menuitem',{name:'Add link',exact:true}).click();
|
||||
await page.getByRole('textbox',{name:'Find a file'}).fill('second');
|
||||
await page.keyboard.press('Enter');
|
||||
await page.getByRole('dialog').waitFor({state:'detached'});
|
||||
await page.screenshot({path:`${output}/ide-links.png`});
|
||||
console.log('PASS: empty and whitespace Writer menus, full submenus, disabled actions, links, picker, selection, keyboard focus, two themes, narrow viewport and Source.');
|
||||
});
|
||||
@@ -0,0 +1,126 @@
|
||||
// Footnotes and heading folds: the footnote menu, Reader numbering and backlinks, nested folding, keyboard toggles, and source preservation.
|
||||
import assert from "node:assert/strict";
|
||||
import { chooseView, mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("editor/footnotes", async ({ page }) => {
|
||||
await mockTauri(page, {
|
||||
commands: test => {
|
||||
const workspace = test.workspace({
|
||||
root: "C:\\smoke-workspace",
|
||||
files: {
|
||||
"notes/welcome.md": "---\ntitle: Welcome\n---\n\n# Working notes\n\nFirst paragraph.\n\n- [ ] A task\n\n[[second]]\n",
|
||||
"notes/second.md": "# Second note\n",
|
||||
"src/hello.py": "print('hello')\n",
|
||||
},
|
||||
writeEvents: true,
|
||||
});
|
||||
test.files = workspace.files;
|
||||
return {
|
||||
...workspace,
|
||||
// Saves send the last saved text. Reject a save when the file changed, as the backend does.
|
||||
workspace_write: args => {
|
||||
if (args.expected !== undefined && workspace.files.get(args.rel) !== args.expected) throw new Error("Save blocked: file changed on disk");
|
||||
return workspace.workspace_write(args);
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
const output = await outputDir("editor/footnotes");
|
||||
await page.goto(smokeUrl);
|
||||
await page.getByText("smoke-workspace", { exact: true }).waitFor();
|
||||
await page.keyboard.press("Control+p");
|
||||
await page.getByRole("textbox", { name: "Find a file" }).fill("welcome.md");
|
||||
await page.getByRole("dialog").getByRole("button").filter({ hasText: "welcome.md" }).first().click();
|
||||
await page.getByRole("textbox", { name: "Writing editor", exact: true }).waitFor();
|
||||
async function editor() {
|
||||
await page.evaluate(async () => {
|
||||
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
|
||||
window.__CM__ = EditorView.findFromDOM(document.querySelector(".cm-content"));
|
||||
});
|
||||
}
|
||||
await editor();
|
||||
const source = "# First section\n\nParent text.[^long]\n\n## Child section\n\nChild content.\n\n### Nested section\n\nNested content.\n\n# Second section\n\nSecond content.[^long]\n\n## Last section\n\nFinal content.\n\n[^long]: A **bold** footnote.\n Continued on another line.\n";
|
||||
async function setSource(value) {
|
||||
await page.evaluate(value => window.__CM__.dispatch({ changes: { from: 0, to: window.__CM__.state.doc.length, insert: value }, selection: { anchor: 0 } }), value);
|
||||
}
|
||||
await setSource(source);
|
||||
const structural = "# Parent\n\n| A | B |\n| --- | --- |\n| 1 | 2 |\n\n```md\n# Not a heading\n```\n\n## Child\n\nText\n\n# Next\n\nNext text\n";
|
||||
await setSource(structural);
|
||||
assert.equal(await page.getByRole("button", { name: "Collapse Not a heading", exact: true }).count(), 0);
|
||||
await page.getByRole("button", { name: "Collapse Parent", exact: true }).click();
|
||||
assert.equal(await page.locator(".writer-table").count(), 0);
|
||||
assert.equal(await page.getByRole("button", { name: "Collapse Child", exact: true }).count(), 0);
|
||||
await page.getByRole("button", { name: "Expand Parent", exact: true }).click();
|
||||
await page.locator(".writer-table").waitFor();
|
||||
assert.equal(await page.evaluate(() => window.__CM__.state.sliceDoc()), structural);
|
||||
await setSource("Setext heading\n==============\n\nBody\n\n# Next\n\nNext body");
|
||||
await page.getByRole("button", { name: "Collapse Setext heading", exact: true }).click();
|
||||
await page.getByRole("button", { name: "Expand Setext heading", exact: true }).click();
|
||||
await setSource(source);
|
||||
await page.getByRole("button", { name: "Collapse Child section", exact: true }).click();
|
||||
await page.getByRole("button", { name: "Expand Child section", exact: true }).waitFor();
|
||||
assert.equal(await page.locator(".cm-content").textContent().then(text => text.includes("Child content.")), false);
|
||||
await page.getByRole("button", { name: "Collapse First section", exact: true }).click();
|
||||
assert.equal(await page.getByRole("button", { name: "Expand Child section", exact: true }).count(), 0);
|
||||
await page.getByRole("button", { name: "Expand First section", exact: true }).click();
|
||||
await page.getByRole("button", { name: "Expand Child section", exact: true }).waitFor();
|
||||
await page.getByRole("button", { name: "Expand Child section", exact: true }).focus();
|
||||
await page.keyboard.press("Enter");
|
||||
await page.getByRole("button", { name: "Collapse Child section", exact: true }).waitFor();
|
||||
assert.equal(await page.evaluate(() => document.activeElement?.getAttribute('aria-label')), 'Collapse Child section');
|
||||
assert.equal(await page.evaluate(() => window.__CM__.state.sliceDoc()), source);
|
||||
|
||||
// Insert from the real shared menu and edit the selected definition.
|
||||
await page.evaluate(() => { window.__CM__.dispatch({ selection: { anchor: 20 } }); window.__CM__.focus(); });
|
||||
await page.keyboard.press("Shift+F10");
|
||||
await page.getByRole("menuitem", { name: "Insert", exact: true }).hover();
|
||||
await page.getByRole("menuitem", { name: "Footnote", exact: true }).click();
|
||||
await page.keyboard.type("New footnote");
|
||||
assert.match(await page.evaluate(() => window.__CM__.state.sliceDoc()), /\[\^1\]: New footnote/);
|
||||
await page.keyboard.press("Control+z");
|
||||
await setSource(source);
|
||||
|
||||
for (const theme of ["light", "dark"]) {
|
||||
await page.evaluate(async theme => { const { applyAppearance } = await import('/src/lib/theme/appearance.ts'); applyAppearance({ theme: 'default', mode: theme }); }, theme);
|
||||
await page.setViewportSize({ width: 760, height: 900 });
|
||||
await page.getByRole("button", { name: "Collapse Child section", exact: true }).click();
|
||||
await page.getByRole("button", { name: "Expand Child section", exact: true }).focus();
|
||||
assert.ok(await page.getByRole("button", { name: "Expand Child section", exact: true }).evaluate(button => {
|
||||
const bounds = button.getBoundingClientRect();
|
||||
const pane = button.closest('.cm-scroller').getBoundingClientRect();
|
||||
return bounds.left >= pane.left && bounds.right <= pane.right;
|
||||
}));
|
||||
await page.screenshot({ path: `${output}/writer-${theme}-narrow.png` });
|
||||
await page.keyboard.press("Space");
|
||||
const borders = await page.locator(".writer-heading").evaluateAll(headings => headings.map(heading => getComputedStyle(heading).borderBottomWidth));
|
||||
assert.ok(borders.every(border => border === "0px"));
|
||||
assert.ok(await page.locator(".writer-heading").first().evaluate(heading => parseFloat(getComputedStyle(heading).paddingTop) > 8));
|
||||
await chooseView(page, "Read");
|
||||
await page.locator(".md-footnotes").waitFor();
|
||||
assert.equal(await page.locator(".md-footnote-ref").count(), 2);
|
||||
assert.equal(await page.locator(".md-footnotes li").count(), 1);
|
||||
assert.equal(await page.locator(".md-footnote-back").count(), 2);
|
||||
await page.getByRole("button", { name: "Collapse Child section", exact: true }).click();
|
||||
await page.getByRole("button", { name: "Expand Child section", exact: true }).focus();
|
||||
assert.ok(await page.getByRole("button", { name: "Expand Child section", exact: true }).evaluate(button => {
|
||||
const bounds = button.getBoundingClientRect();
|
||||
const pane = button.closest('.reading').parentElement.getBoundingClientRect();
|
||||
return bounds.left >= pane.left && bounds.right <= pane.right;
|
||||
}));
|
||||
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.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);
|
||||
await page.locator(".md-footnote-back").first().click();
|
||||
assert.equal(await page.evaluate(() => document.activeElement?.id), "rs-fnref-1-1");
|
||||
await chooseView(page, "Write");
|
||||
await page.getByRole("textbox", { name: "Writing editor", exact: true }).waitFor();
|
||||
await editor();
|
||||
}
|
||||
await page.keyboard.press("Control+s");
|
||||
await page.waitForFunction(value => window.__TEST__.files.get("notes/welcome.md") === value, source);
|
||||
console.log("PASS: footnote menu, Writer edits, Reader numbering and backlinks, nested folding, keyboard toggles, source preservation, light/dark narrow screenshots.");
|
||||
});
|
||||
@@ -0,0 +1,153 @@
|
||||
// Images dragged from the file tree: hidden source, selection, image menu actions, cancel, and source mode.
|
||||
import assert from "node:assert/strict";
|
||||
import { chooseView, mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("editor/imageNavigation", async ({ page }) => {
|
||||
await mockTauri(page, {
|
||||
commands: test => {
|
||||
// Image files hold base64 SVG.
|
||||
const svg = btoa('<svg xmlns="http://www.w3.org/2000/svg" width="640" height="360"><rect width="640" height="360" fill="#486077"/><circle cx="320" cy="180" r="110" fill="#93cab5"/></svg>');
|
||||
const workspace = test.workspace({
|
||||
root: "C:\\smoke-workspace",
|
||||
files: {
|
||||
"notes/welcome.md": "Above.\n\nBelow.\n",
|
||||
"notes/second.md": "# Second note\n",
|
||||
"src/hello.py": "print('hello')\n",
|
||||
"images/picture (#1).svg": svg,
|
||||
"images/replacement.svg": svg,
|
||||
},
|
||||
writeEvents: true,
|
||||
});
|
||||
test.files = workspace.files;
|
||||
return {
|
||||
...workspace,
|
||||
// Saves send the last saved text. Reject a save when the file changed, as the backend does.
|
||||
workspace_write: args => {
|
||||
if (args.expected !== undefined && workspace.files.get(args.rel) !== args.expected) throw new Error("Save blocked: file changed on disk");
|
||||
return workspace.workspace_write(args);
|
||||
},
|
||||
workspace_read_data_url: ({ rel }) => {
|
||||
if (!workspace.files.has(rel)) throw new Error("missing image");
|
||||
return "data:image/svg+xml;base64," + workspace.files.get(rel);
|
||||
},
|
||||
workspace_reveal: () => null,
|
||||
};
|
||||
},
|
||||
});
|
||||
const output = await outputDir("editor/imageNavigation");
|
||||
async function writer() {
|
||||
await page.locator(".cm-content").waitFor();
|
||||
await page.evaluate(async () => {
|
||||
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
|
||||
window.__CM__ = EditorView.findFromDOM(document.querySelector(".cm-content"));
|
||||
});
|
||||
}
|
||||
async function source() { return page.evaluate(() => window.__CM__.state.doc.toString()); }
|
||||
async function dragFromTree(selector = ".cm-content", cancel = false) {
|
||||
const row = page.locator('[data-tree-rel="images/picture (#1).svg"]');
|
||||
const from = await row.boundingBox(), to = await page.locator(selector).boundingBox();
|
||||
await page.mouse.move(from.x + 60, from.y + from.height / 2);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(to.x + 40, to.y + 10, { steps: 12 });
|
||||
await page.getByText("Insert image", { exact: true }).waitFor();
|
||||
assert.equal(await page.locator(".image-drop-target").count(), 1);
|
||||
if (cancel) await page.keyboard.press("Escape");
|
||||
await page.mouse.up();
|
||||
}
|
||||
async function imageMenu() {
|
||||
await page.locator(".md-image-frame").first().click({ button: "right" });
|
||||
await page.getByRole("menu", { name: "Image actions" }).waitFor();
|
||||
}
|
||||
await page.context().grantPermissions(["clipboard-read", "clipboard-write"]);
|
||||
await page.goto(smokeUrl);
|
||||
await page.getByText("smoke-workspace", { exact: true }).waitFor();
|
||||
await page.keyboard.press("Control+p");
|
||||
await page.getByRole("textbox", { name: "Find a file" }).fill("welcome.md");
|
||||
await page.getByRole("dialog").getByRole("button").filter({ hasText: "welcome.md" }).click();
|
||||
await writer();
|
||||
await page.locator('[data-tree-rel="images"]').click();
|
||||
await dragFromTree();
|
||||
await page.locator(".md-image-frame img").waitFor();
|
||||
const linked = await source();
|
||||
assert.ok(linked.startsWith("\n\nAbove."), linked);
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.calls.filter(c => ["workspace_write_bytes", "workspace_rename"].includes(c.command)).length), 0);
|
||||
assert.equal(await page.locator(".cm-line").filter({ hasText: "picture%20" }).count(), 0);
|
||||
// Neither caret movement nor selection exposes an image's Markdown.
|
||||
await page.evaluate(() => window.__CM__.dispatch({ selection: { anchor: 0, head: 38 } }));
|
||||
assert.equal(await page.locator(".cm-line").filter({ hasText: "picture%20" }).count(), 0);
|
||||
await page.locator(".md-image-frame img").click();
|
||||
assert.equal(await page.locator(".md-image-frame.is-selected").count(), 1);
|
||||
await page.keyboard.press("Shift+F10");
|
||||
await page.getByRole("menu", { name: "Image actions" }).waitFor();
|
||||
assert.equal(await page.locator(".md-image-frame.is-selected").count(), 1);
|
||||
await page.screenshot({ path: `${output}/image-context-menu.png` });
|
||||
await page.getByRole("menuitem", { name: "Copy Markdown", exact: true }).click();
|
||||
assert.equal(await page.evaluate(() => navigator.clipboard.readText()), "");
|
||||
await imageMenu();
|
||||
await page.getByRole("menuitem", { name: "Copy image", exact: true }).click();
|
||||
await page.waitForFunction(async () => (await navigator.clipboard.read()).some(item => item.types.includes("image/png")));
|
||||
await imageMenu();
|
||||
await page.getByRole("menuitem", { name: "Show in Explorer", exact: true }).click();
|
||||
await page.waitForFunction(() => window.__TEST__.calls.some(c => c.command === "workspace_reveal" && c.args.rel === "images/picture (#1).svg"));
|
||||
await imageMenu();
|
||||
await page.getByRole("menuitem", { name: "Remove image", exact: true }).click();
|
||||
assert.ok(!(await source()).includes("picture%20"));
|
||||
assert.ok(await page.evaluate(() => window.__TEST__.files.has("images/picture (#1).svg")));
|
||||
await page.keyboard.press("Control+z");
|
||||
assert.equal(await source(), linked);
|
||||
|
||||
await page.locator(".md-image-frame").hover();
|
||||
await page.getByRole("button", { name: "Edit image source", exact: true }).click();
|
||||
await page.locator(".cm-line").filter({ hasText: "picture%20" }).waitFor();
|
||||
assert.equal(await page.locator(".md-image-frame img").count(), 1);
|
||||
await page.getByRole("button", { name: "Hide image source", exact: true }).click();
|
||||
assert.equal(await page.locator(".cm-line").filter({ hasText: "picture%20" }).count(), 0);
|
||||
await imageMenu();
|
||||
await page.getByRole("menuitem", { name: "Swap image…", exact: true }).click();
|
||||
await page.getByRole("textbox", { name: "Image path relative to this note, or https URL" }).fill("../images/replacement.svg");
|
||||
await page.getByRole("button", { name: "Continue", exact: true }).click();
|
||||
await page.waitForFunction(() => window.__CM__.state.doc.toString().includes("replacement.svg"));
|
||||
assert.equal(await page.locator(".cm-line").filter({ hasText: "replacement.svg" }).count(), 0);
|
||||
await imageMenu();
|
||||
await page.getByRole("menuitem", { name: "Open in new tab", exact: true }).click();
|
||||
await page.getByRole("tab", { name: "replacement.svg", exact: true }).waitFor();
|
||||
await page.getByRole("tab", { name: /welcome.md/ }).click();
|
||||
await writer();
|
||||
|
||||
const beforeCancel = await source();
|
||||
await dragFromTree(".cm-content", true);
|
||||
assert.equal(await source(), beforeCancel);
|
||||
assert.equal(await page.locator(".image-drop-target").count(), 0);
|
||||
// Inline images remain independently selectable without hiding adjacent prose.
|
||||
await page.evaluate(() => {
|
||||
const view = window.__CM__;
|
||||
view.dispatch({ changes: { from: 0, to: view.state.doc.length, insert: "Before  between ![[../images/replacement.svg]] after.\n" }, selection: { anchor: 0 } });
|
||||
});
|
||||
await page.waitForFunction(() => document.querySelectorAll(".md-image-frame").length === 2);
|
||||
assert.ok((await page.locator(".cm-content").innerText()).includes("Before"));
|
||||
assert.ok(!(await page.locator(".cm-content").innerText()).includes("![]"));
|
||||
await page.locator(".md-image-frame img").nth(1).click();
|
||||
await page.keyboard.press("Delete");
|
||||
assert.equal(await source(), "Before  between after.\n");
|
||||
await page.keyboard.press("Control+z");
|
||||
assert.ok((await source()).includes("![[../images/replacement.svg]]"));
|
||||
// Reference-image editing affects only the selected embed, not its definition.
|
||||
await page.evaluate(() => {
|
||||
const view = window.__CM__;
|
||||
view.dispatch({ changes: { from: 0, to: view.state.doc.length, insert: "![Reference][pic]\n\nBelow.\n\n[pic]: ../images/replacement.svg\n" }, selection: { anchor: 0 } });
|
||||
});
|
||||
await page.locator(".md-image-frame").hover();
|
||||
assert.equal(await page.locator(".cm-line").filter({ hasText: "![Reference]" }).count(), 0);
|
||||
await page.getByRole("button", { name: "Edit image source", exact: true }).click();
|
||||
await page.locator(".cm-line").filter({ hasText: "![Reference]" }).waitFor();
|
||||
await page.keyboard.press("Escape");
|
||||
assert.equal(await page.locator(".cm-line").filter({ hasText: "![Reference]" }).count(), 0);
|
||||
// The same navigator drag works in the source editor.
|
||||
await chooseView(page, "Source");
|
||||
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);
|
||||
console.log("Navigator image drag, hidden source, selection, copy, swap, remove, open, reveal, cancel and source mode passed.");
|
||||
});
|
||||
@@ -0,0 +1,251 @@
|
||||
// Image drops and pastes: unique attachments, live source, zoom, delayed writes, source mode, and undo.
|
||||
import assert from "node:assert/strict";
|
||||
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("editor/images", async ({ page }) => {
|
||||
await mockTauri(page, {
|
||||
commands: test => {
|
||||
const workspace = test.workspace({
|
||||
root: "C:\\smoke-workspace",
|
||||
files: {
|
||||
"notes/welcome.md": "---\ntitle: Welcome\n---\n\n# Working notes\n\nFirst paragraph.\n\n- [ ] A task\n\n[[second]]\n",
|
||||
"notes/second.md": "# Second note\n",
|
||||
"src/hello.py": "print('hello')\n",
|
||||
},
|
||||
writeEvents: true,
|
||||
});
|
||||
test.files = workspace.files;
|
||||
return {
|
||||
...workspace,
|
||||
// Saves send the last saved text. Reject a save when the file changed, as the backend does.
|
||||
workspace_write: args => {
|
||||
if (args.expected !== undefined && workspace.files.get(args.rel) !== args.expected) throw new Error("Save blocked: file changed on disk");
|
||||
return workspace.workspace_write(args);
|
||||
},
|
||||
// Image files hold base64 SVG. Tests set `delay` to hold a write until `resume()`, or `failWrite` to reject it.
|
||||
workspace_write_bytes: async args => {
|
||||
if (test.delay) await new Promise(resolve => { test.resume = resolve; });
|
||||
if (test.failWrite) throw new Error("Image write failed");
|
||||
workspace.files.set(args.rel, args.base64);
|
||||
},
|
||||
// The download of a copied web image. The host adds the extension of the downloaded format.
|
||||
workspace_save_image_url: args => {
|
||||
if (args.url.includes("offline")) throw new Error("Cannot reach the image server");
|
||||
const rel = args.rel + ".gif";
|
||||
workspace.files.set(rel, btoa('<svg xmlns="http://www.w3.org/2000/svg" width="10" height="10"/>'));
|
||||
return rel;
|
||||
},
|
||||
workspace_read_data_url: ({ rel }) => {
|
||||
if (!workspace.files.has(rel)) throw new Error("missing image");
|
||||
return "data:image/svg+xml;base64," + workspace.files.get(rel);
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
const output = await outputDir("editor/images");
|
||||
async function openNote(name = "welcome.md") {
|
||||
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.locator(".cm-content").waitFor();
|
||||
}
|
||||
async function source() {
|
||||
return page.evaluate(() => window.__CM__.state.doc.toString());
|
||||
}
|
||||
async function save() {
|
||||
await page.keyboard.press("Control+s");
|
||||
await page.waitForTimeout(100);
|
||||
return page.evaluate(() => window.__TEST__.files.get("notes/welcome.md"));
|
||||
}
|
||||
async function drop(count = 1, selector = ".cm-content") {
|
||||
await page.locator(selector).evaluate((element, count) => {
|
||||
const data = new DataTransfer();
|
||||
const svg = '<svg xmlns="http://www.w3.org/2000/svg" width="900" height="600"><rect width="900" height="600" fill="#536174"/><circle cx="450" cy="260" r="140" fill="#99c9b5"/><text x="450" y="480" text-anchor="middle" font-size="40" fill="white">Image drop test</text></svg>';
|
||||
for (let i = 0; i < count; i++) data.items.add(new File([svg], "picture.svg", { type: "" }));
|
||||
const rect = element.getBoundingClientRect();
|
||||
element.dispatchEvent(new DragEvent("drop", { bubbles: true, cancelable: true, dataTransfer: data, clientX: rect.left + 20, clientY: rect.top + 8 }));
|
||||
}, count);
|
||||
}
|
||||
await page.goto(smokeUrl);
|
||||
await page.getByText("smoke-workspace", { exact: true }).waitFor();
|
||||
await openNote();
|
||||
await page.evaluate(async () => {
|
||||
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
|
||||
window.__CM__ = EditorView.findFromDOM(document.querySelector(".cm-content"));
|
||||
window.__CM__.dispatch({ changes: { from: 0, to: window.__CM__.state.doc.length, insert: "First paragraph.\n\nLast paragraph.\n" } });
|
||||
});
|
||||
const original = await source();
|
||||
const acceptsDrag = await page.locator(".cm-content").evaluate(element => {
|
||||
const data = new DataTransfer(); data.items.add(new File(["x"], "test.svg"));
|
||||
const event = new DragEvent("dragover", { bubbles: true, cancelable: true, dataTransfer: data });
|
||||
element.dispatchEvent(event); return event.defaultPrevented;
|
||||
});
|
||||
assert.ok(acceptsDrag);
|
||||
await drop(2);
|
||||
await page.waitForFunction(() => (window.__CM__.state.doc.toString().match(/!\[\]/g) || []).length === 2);
|
||||
await page.locator(".md-image-frame img").first().waitFor();
|
||||
assert.equal(await page.locator(".md-image-frame img").count(), 2);
|
||||
const inserted = await source();
|
||||
assert.ok(inserted.indexOf("![]") < inserted.indexOf("First paragraph."), "drop inserts at pointer, not stale cursor");
|
||||
const paths = [...inserted.matchAll(/!\[\]\(([^)]+)\)/g)].map(match => match[1]);
|
||||
assert.notEqual(paths[0], paths[1]);
|
||||
assert.ok(paths.every(path => path.startsWith("../attachments/")));
|
||||
assert.equal(await save(), inserted);
|
||||
|
||||
// Selecting and editing Markdown leaves the image visible and updates its alt text.
|
||||
await page.locator(".md-image-frame").first().hover();
|
||||
await page.getByRole("button", { name: "Edit image source", exact: true }).first().click();
|
||||
assert.equal(await page.locator(".md-image-frame img").count(), 2);
|
||||
assert.ok((await page.locator(".cm-line").allTextContents()).some(line => line.includes(paths[0])));
|
||||
await page.evaluate(() => {
|
||||
const view = window.__CM__, from = view.state.doc.toString().indexOf("![]") + 2;
|
||||
view.dispatch({ changes: { from, insert: "Edited alt" }, selection: { anchor: from + 10 } });
|
||||
});
|
||||
await page.locator('img[alt="Edited alt"]').waitFor();
|
||||
await page.screenshot({ path: `${output}/images-editing.png` });
|
||||
await page.locator(".md-image-frame").first().hover();
|
||||
await page.getByRole("button", { name: "Zoom in", exact: true }).first().click();
|
||||
const zoom = page.getByRole("dialog", { name: "Image zoom" });
|
||||
await zoom.waitFor();
|
||||
await zoom.getByRole("button", { name: "Zoom in", exact: true }).click();
|
||||
assert.equal(await zoom.locator(".image-lightbox-scale").textContent(), "100%");
|
||||
await zoom.getByRole("button", { name: "Zoom in", exact: true }).click();
|
||||
assert.equal(await zoom.locator(".image-lightbox-scale").textContent(), "200%");
|
||||
await page.screenshot({ path: `${output}/images-zoom.png` });
|
||||
await zoom.getByRole("button", { name: "Fit image", exact: true }).click();
|
||||
await page.keyboard.press("Escape");
|
||||
assert.equal(await page.getByRole("dialog").count(), 0);
|
||||
assert.equal(await page.evaluate(() => document.activeElement?.getAttribute("aria-label")), "Zoom in");
|
||||
|
||||
// Undo the alt edit and the complete drop as separate operations.
|
||||
await page.locator(".cm-line").filter({ hasText: "![Edited alt]" }).click();
|
||||
await page.keyboard.press("Control+z");
|
||||
await page.keyboard.press("Control+z");
|
||||
assert.equal(await source(), original);
|
||||
await page.keyboard.press("Control+y");
|
||||
assert.equal(await source(), inserted);
|
||||
|
||||
// Type and move the cursor during a slow import; the drop follows its original position.
|
||||
await page.evaluate(() => { window.__TEST__.delay = true; });
|
||||
await drop();
|
||||
await page.waitForFunction(() => !!window.__TEST__.resume);
|
||||
await page.evaluate(() => {
|
||||
const view = window.__CM__;
|
||||
view.dispatch({ changes: { from: 0, insert: "Typed while saving.\n\n" }, selection: { anchor: view.state.doc.length } });
|
||||
window.__TEST__.delay = false; window.__TEST__.resume(); window.__TEST__.resume = null;
|
||||
});
|
||||
await page.waitForFunction(() => (window.__CM__.state.doc.toString().match(/!\[\]/g) || []).length === 3);
|
||||
assert.ok((await source()).startsWith("Typed while saving.\n\n![]"));
|
||||
|
||||
// Typed local image paths load without changing views, including wiki syntax.
|
||||
await page.evaluate(path => {
|
||||
window.__TEST__.files.set("attachments/typed.svg", [...window.__TEST__.files].find(([key]) => key.startsWith("attachments/"))[1]);
|
||||
const view = window.__CM__;
|
||||
view.dispatch({ changes: { from: view.state.doc.length, insert: `\n![[${path}|Wiki image]]\n` }, selection: { anchor: view.state.doc.length } });
|
||||
}, "../attachments/typed.svg");
|
||||
await page.locator('img[alt="Wiki image"]').waitFor();
|
||||
await save();
|
||||
await page.getByRole("radiogroup", { name: "View" }).getByRole("radio", { name: "Write", exact: true }).focus();
|
||||
await page.keyboard.press("End");
|
||||
await page.locator(".md-page .md-image-frame").first().hover();
|
||||
await page.locator(".md-page").getByRole("button", { name: "Zoom in", exact: true }).first().click();
|
||||
await page.getByRole("dialog", { name: "Image zoom" }).waitFor();
|
||||
await page.keyboard.press("Escape");
|
||||
|
||||
// Source uses the same drop flow. The batch is one undo step.
|
||||
await page.getByRole("radiogroup", { name: "View" }).getByRole("radio", { name: "Read", exact: true }).focus();
|
||||
await page.keyboard.press("Home");
|
||||
await page.keyboard.press("Control+e");
|
||||
await page.locator(".source-editor .cm-content").waitFor();
|
||||
await page.evaluate(async () => {
|
||||
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
|
||||
window.__CM__ = EditorView.findFromDOM(document.querySelector(".source-editor .cm-content"));
|
||||
});
|
||||
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 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 source();
|
||||
await page.evaluate(() => { window.__TEST__.failWrite = true; });
|
||||
await drop(1, ".source-editor .cm-content");
|
||||
await page.getByText("Image write failed", { exact: true }).waitFor();
|
||||
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.
|
||||
await page.keyboard.press("Control+e");
|
||||
await page.locator(".cm-content").waitFor();
|
||||
await page.evaluate(async () => {
|
||||
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
|
||||
window.__CM__ = EditorView.findFromDOM(document.querySelector(".cm-content"));
|
||||
});
|
||||
await drop(1, ".md-image-frame img >> nth=0");
|
||||
await page.waitForFunction(() => (window.__CM__.state.doc.toString().match(/!\[\]/g) || []).length === 6);
|
||||
|
||||
// Switching tabs while a write is pending cannot insert into the new document.
|
||||
await page.evaluate(() => { window.__TEST__.delay = true; });
|
||||
await drop();
|
||||
await page.waitForFunction(() => !!window.__TEST__.resume);
|
||||
await openNote("second.md");
|
||||
await page.evaluate(() => { window.__TEST__.delay = false; window.__TEST__.resume(); });
|
||||
await page.waitForTimeout(100);
|
||||
assert.ok(!(await page.locator(".cm-content").textContent()).includes("attachments/"));
|
||||
// Clipboard images are inserted and remain a single undo operation too.
|
||||
await page.locator(".cm-content").evaluate(element => {
|
||||
const data = new DataTransfer();
|
||||
data.items.add(new File(['<svg xmlns="http://www.w3.org/2000/svg" width="10" height="10"/>'], "pasted.svg", { type: "image/svg+xml" }));
|
||||
element.dispatchEvent(new ClipboardEvent("paste", { bubbles: true, cancelable: true, clipboardData: data }));
|
||||
});
|
||||
await page.waitForFunction(() => document.querySelector(".md-image-frame img"));
|
||||
await page.keyboard.press("Control+s");
|
||||
await page.waitForFunction(() => window.__TEST__.files.get("notes/second.md").includes("pasted.svg"));
|
||||
// A browser copies the still first frame of a GIF. RuneStone saves the original file from the address in the HTML.
|
||||
async function pasteWebImage(src) {
|
||||
await page.locator(".cm-content").evaluate((element, src) => {
|
||||
const data = new DataTransfer();
|
||||
data.items.add(new File(["png"], "image.png", { type: "image/png" }));
|
||||
data.setData("text/html", `<html><body>\r\n<!--StartFragment--><img src="${src}"/><!--EndFragment-->\r\n</body>\r\n</html>`);
|
||||
element.dispatchEvent(new ClipboardEvent("paste", { bubbles: true, cancelable: true, clipboardData: data }));
|
||||
}, src);
|
||||
}
|
||||
await page.evaluate(async () => {
|
||||
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
|
||||
window.__CM__ = EditorView.findFromDOM(document.querySelector(".cm-content"));
|
||||
});
|
||||
const writes = () => page.evaluate(() => window.__TEST__.calls.filter(call => call.command === "workspace_write_bytes").length);
|
||||
const writesBefore = await writes();
|
||||
await pasteWebImage("https://media.example.com/cat.gif?size=large&v=2");
|
||||
await page.waitForFunction(() => /attachments\/[\w-]+-image\.gif\)/.test(window.__CM__.state.doc.toString()));
|
||||
const download = await page.evaluate(() => window.__TEST__.calls.find(call => call.command === "workspace_save_image_url").args);
|
||||
assert.equal(download.url, "https://media.example.com/cat.gif?size=large&v=2");
|
||||
assert.match(download.rel, /^attachments\/[\w-]+-image$/);
|
||||
assert.equal(await writes(), writesBefore);
|
||||
// When the download fails, the still copy stays.
|
||||
await pasteWebImage("https://offline.example.com/cat.gif");
|
||||
await page.waitForFunction(() => /attachments\/[\w-]+-image\.png\)/.test(window.__CM__.state.doc.toString()));
|
||||
assert.equal(await writes(), writesBefore + 1);
|
||||
await page.getByText("The website refused the original image, so RuneStone added only its first frame.", { exact: false }).waitFor();
|
||||
// The RuneStone browser keeps the bytes of the image that it copied. The website gets no second request.
|
||||
await page.evaluate(async () => (await import("/src/lib/workspace/copiedImage.ts")).keepCopiedImage("https://offline.example.com/copied.gif",
|
||||
Promise.resolve("data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7")));
|
||||
const downloads = () => page.evaluate(() => window.__TEST__.calls.filter(call => call.command === "workspace_save_image_url").length);
|
||||
const downloadsBefore = await downloads();
|
||||
await pasteWebImage("https://offline.example.com/copied.gif");
|
||||
await page.waitForFunction(() => (window.__CM__.state.doc.toString().match(/-image\.gif\)/g) || []).length === 2);
|
||||
assert.equal(await downloads(), downloadsBefore);
|
||||
assert.match(await page.evaluate(() => window.__TEST__.calls.findLast(call => call.command === "workspace_write_bytes").args.rel), /-image\.gif$/);
|
||||
// An empty file from a browser drag gives a message, not a broken image.
|
||||
await page.locator(".cm-content").evaluate(element => {
|
||||
const data = new DataTransfer();
|
||||
data.items.add(new File([], "viprsr188.gif", { type: "image/gif" }));
|
||||
const rect = element.getBoundingClientRect();
|
||||
element.dispatchEvent(new DragEvent("drop", { bubbles: true, cancelable: true, dataTransfer: data, clientX: rect.left + 20, clientY: rect.top + 8 }));
|
||||
});
|
||||
await page.getByText("The image file is empty.", { exact: false }).waitFor();
|
||||
assert.ok(!(await page.evaluate(() => window.__CM__.state.doc.toString())).includes("viprsr188"));
|
||||
console.log("Image drops, unique attachments, live source, zoom, async insertion, source mode, undo, web GIF pastes, copied originals, and empty files passed.");
|
||||
});
|
||||
@@ -0,0 +1,129 @@
|
||||
// Writer interactions: code selection and copy, caret and scroll restore, Ctrl+click links, shared heading typography, and spelling targets.
|
||||
import assert from "node:assert/strict";
|
||||
import { chooseView, mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("editor/interactions", async ({ page }) => {
|
||||
await page.context().grantPermissions(["clipboard-read", "clipboard-write"]);
|
||||
await mockTauri(page, {
|
||||
commands: test => ({
|
||||
...test.workspace({
|
||||
root: "C:\\editor-interactions-smoke",
|
||||
files: {
|
||||
"note.md": "# Stack\n\nHardware can be reused.\nAssume speeds of 1 Gb/s.\n\n## Hardware\n\n### Router\n\n- [ ] First task\n- [ ] Second task\n\n[Local](other.md) and [Web](https://example.com) and [[other|Wiki]]\n\n```sh\npnpm install --frozen-lockfile\npnpm check\npnpm test\n```\n\n" + Array.from({ length: 80 }, (_, i) => `Paragraph ${i}.\n\n`).join("") + "```js\nconst preserve = 42;\nconsole.log(preserve);\n```\n",
|
||||
"other.md": "# Other document\n\nKeep the original tab.\n",
|
||||
},
|
||||
}),
|
||||
"plugin:opener|open_url": () => null,
|
||||
spelling_menu_install: () => null,
|
||||
}),
|
||||
});
|
||||
async function writer() {
|
||||
await page.locator(".cm-content").waitFor();
|
||||
await page.evaluate(async () => {
|
||||
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
|
||||
window.writerView = EditorView.findFromDOM(document.querySelector(".cm-content"));
|
||||
});
|
||||
}
|
||||
async function top() {
|
||||
await writer();
|
||||
await page.evaluate(() => { window.writerView.dispatch({ selection: { anchor: 0 } }); window.writerView.scrollDOM.scrollTop = 0; });
|
||||
}
|
||||
await page.goto(smokeUrl);
|
||||
await page.locator('[data-tree-rel="note.md"]').dblclick();
|
||||
await writer();
|
||||
const code = page.locator(".writer-code-line").filter({ hasText: "pnpm install" });
|
||||
await code.scrollIntoViewIfNeeded();
|
||||
const points = await page.evaluate(() => {
|
||||
const view = window.writerView, from = view.state.doc.toString().indexOf("pnpm install");
|
||||
return { from: view.coordsAtPos(from), to: view.coordsAtPos(from + 12) };
|
||||
});
|
||||
await page.mouse.move(points.from.left + 1, (points.from.top + points.from.bottom) / 2);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(points.to.left, (points.to.top + points.to.bottom) / 2, { steps: 8 });
|
||||
await page.mouse.up();
|
||||
assert.match(await page.evaluate(() => { const view = window.writerView; return view.state.sliceDoc(view.state.selection.main.from, view.state.selection.main.to); }), /pnpm install/);
|
||||
// A selection inside a code block shows its source and hides the copy button (src/lib/editor/liveMarkdown.ts:246-247).
|
||||
// Move the caret out of the block, as a reader would before copying.
|
||||
await page.evaluate(() => { window.writerView.dispatch({ selection: { anchor: 0 } }); });
|
||||
await page.getByRole("button", { name: "Copy code", exact: true }).first().click();
|
||||
assert.equal((await page.evaluate(() => navigator.clipboard.readText())).replace(/\r\n/g, "\n"), "pnpm install --frozen-lockfile\npnpm check\npnpm test\n");
|
||||
console.log("PASS: first drag selects code and the copy button copies only the code body");
|
||||
|
||||
await page.evaluate(() => { const view = window.writerView; view.dispatch({ selection: { anchor: view.state.doc.toString().indexOf("preserve =") + 5 }, scrollIntoView: true }); view.focus(); });
|
||||
await page.keyboard.type("X");
|
||||
await page.waitForTimeout(250);
|
||||
const saved = await page.evaluate(() => ({ head: window.writerView.state.selection.main.head, scroll: window.writerView.scrollDOM.scrollTop, doc: window.writerView.state.sliceDoc(), height: window.writerView.scrollDOM.scrollHeight, caret: window.writerView.coordsAtPos(window.writerView.state.selection.main.head) }));
|
||||
assert.ok(saved.scroll > 1000);
|
||||
await page.locator('[data-tree-rel="other.md"]').dblclick();
|
||||
await writer();
|
||||
await page.getByRole("tab", { name: "note.md", exact: true }).click();
|
||||
await writer();
|
||||
await page.waitForTimeout(250);
|
||||
const restored = await page.evaluate(() => ({ head: window.writerView.state.selection.main.head, scroll: window.writerView.scrollDOM.scrollTop, doc: window.writerView.state.sliceDoc(), height: window.writerView.scrollDOM.scrollHeight, caret: window.writerView.coordsAtPos(window.writerView.state.selection.main.head) }));
|
||||
assert.equal(restored.head, saved.head);
|
||||
assert.equal(restored.doc, saved.doc);
|
||||
assert.ok(Math.abs(restored.caret.top - saved.caret.top) < 3, JSON.stringify({ saved, restored }));
|
||||
await page.evaluate(() => { window.dispatchEvent(new Event("blur")); window.dispatchEvent(new Event("focus")); });
|
||||
await page.waitForTimeout(150);
|
||||
assert.equal(await page.evaluate(() => window.writerView.state.selection.main.head), saved.head);
|
||||
console.log("PASS: code edit, caret, and scroll survive tab and window focus changes");
|
||||
|
||||
await top();
|
||||
await page.locator('.writer-link[data-href="other.md"]').click({ modifiers: ["Control"] });
|
||||
await page.getByRole("tab", { name: "other.md", exact: true }).waitFor();
|
||||
assert.equal(await page.getByRole("tab", { name: "note.md", exact: true }).count(), 1);
|
||||
await page.getByRole("tab", { name: "note.md", exact: true }).click();
|
||||
await top();
|
||||
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(".source-editor .cm-content").waitFor();
|
||||
const linkPoint = 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"));
|
||||
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 { 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"));
|
||||
console.log("PASS: Writer and Source Ctrl+click open workspace links while retaining the source tab");
|
||||
|
||||
await page.getByRole("tab", { name: "note.md", exact: true }).click();
|
||||
await page.keyboard.press("Control+e");
|
||||
await top();
|
||||
const output = await outputDir("editor/interactions");
|
||||
for (const theme of ["dark", "light"]) {
|
||||
await page.evaluate(async mode => {
|
||||
const { applyAppearance, parseAppearance } = await import("/src/lib/theme/appearance.ts");
|
||||
applyAppearance({ ...parseAppearance(null), mode });
|
||||
}, theme);
|
||||
const writing = await page.locator(".writer-h1").first().evaluate(node => { const style = getComputedStyle(node); return { size: style.fontSize, line: style.lineHeight, family: style.fontFamily, weight: style.fontWeight }; });
|
||||
await page.screenshot({ path: `${output}/editor-typography-${theme}.png` });
|
||||
await chooseView(page, "Read");
|
||||
const reading = await page.locator(".reading h1:not(.document-title)").first().evaluate(node => { const style = getComputedStyle(node); return { size: style.fontSize, line: style.lineHeight, family: style.fontFamily, weight: style.fontWeight }; });
|
||||
assert.deepEqual(writing, reading);
|
||||
await page.screenshot({ path: `${output}/reader-typography-${theme}.png` });
|
||||
await chooseView(page, "Write");
|
||||
await top();
|
||||
}
|
||||
await page.setViewportSize({ width: 640, height: 750 });
|
||||
// The outline gives way below 1100 pixels (UI-052). A click on "Hide outline" would race that change.
|
||||
await page.getByRole("button", { name: "Show outline", exact: true }).waitFor();
|
||||
await page.screenshot({ path: `${output}/editor-typography-narrow.png` });
|
||||
assert.ok(await page.locator(".cm-content").evaluate(node => node.getBoundingClientRect().width <= node.closest(".cm-scroller").getBoundingClientRect().width + 1));
|
||||
const spelling = await page.evaluate(async () => {
|
||||
const { isSpellingTarget } = await import("/src/lib/editor/spellingMenu.ts");
|
||||
const area = document.createElement("textarea"); area.spellcheck = true; document.body.append(area);
|
||||
const active = isSpellingTarget(area); area.readOnly = true; const readOnly = isSpellingTarget(area); area.remove();
|
||||
return { active, readOnly };
|
||||
});
|
||||
assert.deepEqual(spelling, { active: true, readOnly: false });
|
||||
console.log("PASS: shared heading typography in both themes, narrow Writer, and textarea spelling target");
|
||||
}, { viewport: { width: 1280, height: 900 }, timeout: 15000 });
|
||||
@@ -0,0 +1,67 @@
|
||||
// Mouse drag selection across a heading and a rendered link keeps the layout stable and selects the hidden link syntax.
|
||||
import assert from "node:assert/strict";
|
||||
import path from "node:path";
|
||||
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("editor/linkSelection", async ({ page }) => {
|
||||
page.setDefaultTimeout(15000);
|
||||
// The original mock returned null for commands it did not handle.
|
||||
await mockTauri(page, {
|
||||
strict: false,
|
||||
commands: test => ({
|
||||
...test.workspace({ root: "C:\\tab-menu-workspace", files: { "a.md": "# Links\n\nOriginal text.\n" }, folders: ["notes"] }),
|
||||
workspace_search: () => [],
|
||||
"plugin:window|is_maximized": () => false,
|
||||
plugins_snapshot: () => ({ root: "C:/plugins", plugins: [] }),
|
||||
spelling_suggestions: () => ({ language: "en-US", words: [], misspelled: false }),
|
||||
"plugin:dialog|message": () => "Cancel",
|
||||
}),
|
||||
});
|
||||
const output = await outputDir("editor/linkSelection");
|
||||
async function reset(text) {
|
||||
await page.locator(".cm-content").evaluate(async (node, text) => {
|
||||
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
|
||||
const view = EditorView.findFromDOM(node);
|
||||
view.dispatch({ changes: { from: 0, to: view.state.doc.length, insert: text }, selection: { anchor: 0 } });
|
||||
view.focus();
|
||||
}, text);
|
||||
}
|
||||
async function selected() {
|
||||
return page.locator(".cm-content").evaluate(async node => {
|
||||
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
|
||||
const view = EditorView.findFromDOM(node), range = view.state.selection.main;
|
||||
return view.state.sliceDoc(range.from, range.to);
|
||||
});
|
||||
}
|
||||
|
||||
await page.goto(smokeUrl);
|
||||
await page.locator('[data-tree-rel="a.md"]').click();
|
||||
await page.locator(".cm-content").waitFor();
|
||||
await page.getByRole("button", { name: "Files", exact: true }).click();
|
||||
await page.getByRole("button", { name: "Hide outline", exact: true }).click();
|
||||
for (const theme of ["dark", "light"]) for (const width of [1440, 620]) {
|
||||
await page.setViewportSize({ width, height: 1000 });
|
||||
await page.evaluate(async mode => (await import("/src/lib/theme/appearance.ts")).saveAppearance({ theme: "default", mode }), theme);
|
||||
for (const link of ["[gpt-oss-120b-heretic](https://huggingface.co/kldzj/gpt-oss-120b-heretic)", "[[models/gpt-oss-120b-heretic|gpt-oss-120b-heretic]]"]) {
|
||||
const heading = "### Agentic Coding (DeepSWE 1.1)";
|
||||
const text = "Outside.\n\n" + heading + "\n" + link + "\n\nEnd.";
|
||||
for (const reverse of [false, true]) {
|
||||
await reset(text);
|
||||
const title = await page.locator(".cm-line").filter({ hasText: "Agentic Coding" }).boundingBox();
|
||||
const label = await page.locator(".writer-link").boundingBox();
|
||||
const start = { x: title.x + 1, y: title.y + title.height / 2 };
|
||||
const end = { x: label.x + label.width + 2, y: label.y + label.height / 2 };
|
||||
await page.mouse.move(reverse ? end.x : start.x, reverse ? end.y : start.y);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(reverse ? start.x : end.x, reverse ? start.y : end.y, { steps: 12 });
|
||||
await page.mouse.up();
|
||||
assert.equal(await selected(), heading + "\n" + link, `${theme}/${width}/${reverse}/${link}`);
|
||||
await page.screenshot({ path: path.join(output, `${theme}-${width}-${reverse}-${link.startsWith("[[") ? "wiki" : "markdown"}.png`) });
|
||||
}
|
||||
await reset(text);
|
||||
await page.locator(".writer-link").click({ position: { x: 30, y: 8 } });
|
||||
assert.equal(await selected(), "", "A click places the caret without selecting the link");
|
||||
assert.equal(await page.locator(".writer-link-source").count(), 1);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,116 @@
|
||||
// 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 { chooseView, 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 chooseView(page, "Read");
|
||||
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 chooseView(page, "Write");
|
||||
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="Source"] .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.");
|
||||
});
|
||||
@@ -0,0 +1,155 @@
|
||||
// Markdown text menu in source and writing modes: formatting, paragraphs, tables, links, extraction, clipboard, and stale selections.
|
||||
import assert from "node:assert/strict";
|
||||
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("editor/markdownMenu", async ({ page }) => {
|
||||
await mockTauri(page, {
|
||||
commands: test => {
|
||||
const workspace = test.workspace({
|
||||
root: "C:\\smoke-workspace",
|
||||
files: {
|
||||
"notes/welcome.md": "---\ntitle: Welcome\n---\n\n# Working notes\n\nFirst paragraph.\n\n- [ ] A task\n\n[[second]]\n",
|
||||
"notes/second.md": "# Second note\n",
|
||||
"src/hello.py": "print('hello')\n",
|
||||
},
|
||||
writeEvents: true,
|
||||
});
|
||||
test.files = workspace.files;
|
||||
return {
|
||||
...workspace,
|
||||
// Saves send the last saved text. Reject a save when the file changed, as the backend does.
|
||||
workspace_write: args => {
|
||||
if (args.expected !== undefined && workspace.files.get(args.rel) !== args.expected) throw new Error("Save blocked: file changed on disk");
|
||||
return workspace.workspace_write(args);
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
const output = await outputDir("editor/markdownMenu");
|
||||
async function quickOpen(name) {
|
||||
await page.keyboard.press("Control+p");
|
||||
await page.getByRole("textbox", { name: "Find a file" }).fill(name);
|
||||
await page.getByRole("dialog").getByRole("button").filter({ hasText: name }).first().click();
|
||||
await page.getByRole("tab", { selected: true }).click({ button: "right" });
|
||||
await page.getByRole("menuitem", { name: "View", exact: true }).click();
|
||||
await page.getByRole("menuitemradio", { name: "Source", exact: true }).click();
|
||||
await page.locator(".source-editor .cm-content").waitFor();
|
||||
}
|
||||
async function waitForText(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 { 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");
|
||||
await menu.waitFor();
|
||||
await menu.getByRole("menuitem", { name: "Format", exact: true }).hover();
|
||||
await menu.getByRole("menuitem", { name: "Bold Ctrl+B", exact: true }).click();
|
||||
await waitForText("**First** paragraph.\n\nSecond paragraph.\n");
|
||||
await page.keyboard.press("Control+z"); await waitForText(source);
|
||||
await page.getByRole("tab", { selected: true }).click({ button: "right" });
|
||||
await page.getByRole("menuitem", { name: "View", exact: true }).click();
|
||||
await page.getByRole("menuitemradio", { name: "Write", exact: true }).click();
|
||||
const writer = page.getByRole("textbox", { name: "Writing editor", exact: true });
|
||||
await writer.click(); await page.keyboard.press("Control+Home");
|
||||
await page.keyboard.press("Control+Shift+ArrowRight");
|
||||
await page.keyboard.press("Shift+F10"); await menu.waitFor();
|
||||
await menu.getByRole("menuitem", { name: "Format", exact: true }).hover();
|
||||
await menu.getByRole("menuitem", { name: "Italic Ctrl+I", exact: true }).click();
|
||||
await page.keyboard.press("Control+s");
|
||||
await page.waitForFunction(() => window.__TEST__.files.get("notes/welcome.md") === "*First* paragraph.\n\nSecond paragraph.\n");
|
||||
await page.keyboard.press("Control+z");
|
||||
await page.keyboard.press("Control+Home");
|
||||
await page.keyboard.press("Shift+F10");
|
||||
await menu.getByRole("menuitem", { name: "Paragraph", exact: true }).hover();
|
||||
await menu.getByRole("menuitem", { name: "Heading 2", exact: true }).click();
|
||||
await page.keyboard.press("Control+s");
|
||||
await page.waitForFunction(() => window.__TEST__.files.get("notes/welcome.md").startsWith("## First paragraph."));
|
||||
await page.keyboard.press("Control+z");
|
||||
await page.keyboard.press("Control+End");
|
||||
await page.keyboard.press("Shift+F10");
|
||||
await menu.getByRole("menuitem", { name: "Insert", exact: true }).hover();
|
||||
await menu.getByRole("menuitem", { name: "Table", exact: true }).click();
|
||||
await page.locator(".live-writer table").waitFor();
|
||||
await page.keyboard.press("Control+z");
|
||||
await page.keyboard.press("Control+Home");
|
||||
await page.keyboard.press("Control+Shift+ArrowRight");
|
||||
// Mouse invocation must preserve the selection, too.
|
||||
await page.locator(".cm-line").filter({ hasText: "First paragraph." }).click({ button: "right", position: { x: 12, y: 10 } });
|
||||
await menu.waitFor();
|
||||
await menu.getByRole("menuitem", { name: "Format", exact: true }).hover();
|
||||
await menu.getByRole("menuitem", { name: "Highlight Ctrl+Shift+H", exact: true }).click();
|
||||
await page.keyboard.press("Control+s");
|
||||
await page.waitForFunction(() => window.__TEST__.files.get("notes/welcome.md").startsWith("==First== paragraph."));
|
||||
await page.keyboard.press("Control+End");
|
||||
await page.locator(".writer-highlight").waitFor();
|
||||
assert.equal(await page.locator(".writer-highlight").textContent(), "First");
|
||||
await page.keyboard.press("Control+z");
|
||||
await page.keyboard.press("Control+End");
|
||||
await page.keyboard.press("Shift+F10");
|
||||
await menu.getByRole("menuitem", { name: "Insert", exact: true }).hover();
|
||||
await page.screenshot({ path: `${output}/markdown-insert-menu.png` });
|
||||
await page.keyboard.press("Escape");
|
||||
await page.setViewportSize({ width: 760, height: 600 });
|
||||
await page.evaluate(() => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))));
|
||||
await writer.focus();
|
||||
await page.keyboard.press("Shift+F10");
|
||||
await menu.getByRole("menuitem", { name: "Paragraph", exact: true }).focus();
|
||||
await page.keyboard.press("ArrowRight");
|
||||
assert.equal(await page.evaluate(() => document.activeElement.textContent), "Bullet list");
|
||||
const rect = await menu.getByRole("menu", { name: "Paragraph", exact: true }).boundingBox();
|
||||
assert.ok(rect.x >= 0 && rect.y >= 0 && rect.x + rect.width <= 760 && rect.y + rect.height <= 600);
|
||||
await page.screenshot({ path: `${output}/markdown-paragraph-menu.png` });
|
||||
await page.keyboard.press("ArrowLeft");
|
||||
assert.equal(await page.evaluate(() => document.activeElement.textContent), "Paragraph");
|
||||
await page.keyboard.press("Escape");
|
||||
await page.keyboard.press("Control+Home");
|
||||
await page.keyboard.press("Control+Shift+ArrowRight");
|
||||
await page.keyboard.press("Shift+F10");
|
||||
await menu.getByRole("menuitem", { name: "Add external link Ctrl+K", exact: true }).click();
|
||||
// External links insert `[label]()` with the caret in the URL, without a dialog (src/lib/editor/markdownMenu.ts:57, src/lib/editor/linkCommands.ts:3-8).
|
||||
assert.equal(await page.getByRole("dialog").count(), 0);
|
||||
await page.keyboard.type("https://example.com/a");
|
||||
await page.keyboard.press("Control+s");
|
||||
await page.waitForFunction(() => window.__TEST__.files.get("notes/welcome.md").startsWith("[First](https://example.com/a) paragraph."));
|
||||
// Undo the typed URL, then the link, which restores the selected label.
|
||||
await page.keyboard.press("Control+z");
|
||||
await page.keyboard.press("Control+z");
|
||||
await page.evaluate(async () => {
|
||||
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
|
||||
window.__CM__ = EditorView.findFromDOM(document.querySelector(".cm-content"));
|
||||
});
|
||||
await page.waitForFunction(() => window.__CM__.state.sliceDoc().startsWith("First paragraph."));
|
||||
await page.keyboard.press("Shift+F10");
|
||||
await menu.getByRole("menuitem", { name: "Extract current selection…", exact: true }).click();
|
||||
await page.getByRole("textbox", { name: "Extract selection to a new note (workspace relative path)" }).fill("notes/extracted.md");
|
||||
await page.getByRole("button", { name: "Continue", exact: true }).click();
|
||||
await page.keyboard.press("Control+s");
|
||||
await page.waitForFunction(() => window.__TEST__.files.get("notes/welcome.md").startsWith("[[/notes/extracted.md|First]] paragraph."));
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.files.get("notes/extracted.md")), "First\n");
|
||||
await page.keyboard.press("Control+z");
|
||||
await page.context().grantPermissions(["clipboard-read", "clipboard-write"]);
|
||||
await page.evaluate(() => navigator.clipboard.writeText("Pasted"));
|
||||
await page.keyboard.press("Shift+F10");
|
||||
await menu.getByRole("menuitem", { name: "Paste as plain text", exact: true }).click();
|
||||
await page.waitForFunction(() => document.querySelector(".cm-content")?.textContent.includes("Pasted paragraph."));
|
||||
await page.keyboard.press("Control+s");
|
||||
await page.waitForFunction(() => window.__TEST__.files.get("notes/welcome.md").startsWith("Pasted paragraph."));
|
||||
await page.evaluate(() => { navigator.clipboard.readText = () => new Promise(resolve => { window.__finishPaste = resolve; }); });
|
||||
await page.keyboard.press("Shift+F10");
|
||||
await menu.getByRole("menuitem", { name: "Paste as plain text", exact: true }).click();
|
||||
await writer.focus(); await page.keyboard.press("End"); await page.keyboard.type(" kept");
|
||||
await page.evaluate(async () => { window.__finishPaste("STALE"); await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))); });
|
||||
assert.ok(!(await writer.textContent()).includes("STALE"));
|
||||
assert.ok((await writer.textContent()).includes("kept"));
|
||||
console.log("PASS: Markdown menus in source/writing modes, selection retention, formatting, paragraph conversion, table insertion, undo, keyboard navigation, narrow viewport, links, extraction, clipboard and stale-selection guards.");
|
||||
});
|
||||
@@ -0,0 +1,54 @@
|
||||
// Pasting large Markdown keeps the source exact and renders every bold span.
|
||||
import assert from "node:assert/strict";
|
||||
import { mockTauri, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("editor/markdownPaste", async ({ page }) => {
|
||||
await mockTauri(page, {
|
||||
commands: test => test.workspace({
|
||||
root: "C:\\smoke-workspace",
|
||||
files: {
|
||||
"notes/welcome.md": "---\ntitle: Welcome\n---\n\n# Working notes\n\nFirst paragraph.\n\n- [ ] A task\n\n[[second]]\n",
|
||||
"notes/second.md": "# Second note\n",
|
||||
"src/hello.py": "print('hello')\n",
|
||||
},
|
||||
}),
|
||||
});
|
||||
await page.goto(smokeUrl);
|
||||
await page.getByText("smoke-workspace", { exact: true }).waitFor();
|
||||
await page.keyboard.press("Control+p");
|
||||
await page.getByRole("textbox", { name: "Find a file" }).fill("welcome.md");
|
||||
await page.getByRole("dialog").getByRole("button").filter({ hasText: "welcome.md" }).first().click();
|
||||
await page.getByRole("textbox", { name: "Writing editor", exact: true }).waitFor();
|
||||
await page.evaluate(async () => {
|
||||
const { EditorView } = await import("/node_modules/.vite/deps/@codemirror_view.js");
|
||||
window.__CM__ = EditorView.findFromDOM(document.querySelector(".cm-content"));
|
||||
});
|
||||
for (const count of [3, 1000, 5000]) {
|
||||
const result = await page.evaluate(async count => {
|
||||
const { EditorView } = await import("/node_modules/.vite/deps/@codemirror_view.js");
|
||||
const view = window.__CM__;
|
||||
const source = Array.from({ length: count }, (_, i) => "## Heading " + i + "\n\n**Bold** and *italic*\n\n").join("");
|
||||
view.dispatch({ changes: { from: 0, to: view.state.doc.length, insert: "" } });
|
||||
view.focus();
|
||||
const clipboardData = new DataTransfer();
|
||||
clipboardData.setData("text/plain", source);
|
||||
view.contentDOM.dispatchEvent(new ClipboardEvent("paste", { bubbles: true, cancelable: true, clipboardData }));
|
||||
view.dispatch({ selection: { anchor: 0 } });
|
||||
// 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); } });
|
||||
const marks = [];
|
||||
for (const set of view.state.facet(EditorView.decorations)) {
|
||||
if (typeof set !== "function") set.between(0, view.state.doc.length, (from, to, decoration) => { if (decoration.spec.class === "writer-strong") marks.push(from); });
|
||||
}
|
||||
return { correctSource: view.state.sliceDoc() === source, nodes: nodes.length, marks: marks.length };
|
||||
}, count);
|
||||
console.log({ count, ...result });
|
||||
assert.equal(result.correctSource, true);
|
||||
assert.equal(result.nodes, count);
|
||||
assert.equal(result.marks, count);
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,98 @@
|
||||
// Repeated copy and paste of formatted Markdown stays exact across saves, tab switches, Source switches, and line endings.
|
||||
import assert from "node:assert/strict";
|
||||
import { mockTauri, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("editor/pasteRepeat", async ({ page }) => {
|
||||
await mockTauri(page, {
|
||||
commands: test => {
|
||||
const workspace = test.workspace({
|
||||
root: "C:\\smoke-workspace",
|
||||
files: {
|
||||
"notes/welcome.md": "---\ntitle: Welcome\n---\n\n# Working notes\n\nFirst paragraph.\n\n- [ ] A task\n\n[[second]]\n",
|
||||
"notes/second.md": "# Second note\n",
|
||||
"src/hello.py": "print('hello')\n",
|
||||
},
|
||||
writeEvents: true,
|
||||
});
|
||||
test.files = workspace.files;
|
||||
return {
|
||||
...workspace,
|
||||
// Saves send the last saved text. Reject a save when the file changed, as the backend does.
|
||||
workspace_write: args => {
|
||||
if (args.expected !== undefined && workspace.files.get(args.rel) !== args.expected) throw new Error("Save blocked: file changed on disk");
|
||||
return workspace.workspace_write(args);
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
async function open(name) {
|
||||
await page.keyboard.press('Control+p');
|
||||
await page.getByRole('textbox', { name: 'Find a file' }).fill(name);
|
||||
await page.getByRole('dialog').getByRole('button').filter({ hasText: name }).first().click();
|
||||
}
|
||||
async function writer() {
|
||||
await page.locator('.cm-content').waitFor();
|
||||
return page.evaluate(async () => {
|
||||
const { EditorView } = await import('/node_modules/@codemirror/view/dist/index.js');
|
||||
window.__WRITER__ = EditorView.findFromDOM(document.querySelector('.cm-content'));
|
||||
return window.__WRITER__.state.sliceDoc();
|
||||
});
|
||||
}
|
||||
async function expectWriter(expected) {
|
||||
await writer();
|
||||
try { await page.waitForFunction(text => window.__WRITER__.state.sliceDoc() === text, expected); } catch (error) { console.log({ expectedLength: expected.length, actualLength: (await writer()).length, errors: page.errors }); throw error; }
|
||||
}
|
||||
await page.goto(smokeUrl);
|
||||
await page.getByText('smoke-workspace', { exact: true }).waitFor();
|
||||
const formatted = '# Copied heading\n\n## Links\n\n[Reference](https://example.com) and [[second|Another note]]\n\n**Bold**, *italic*, and `code`.\n\n- A list item\n';
|
||||
await page.evaluate(text => { window.__TEST__.files.set('notes/source.md', text); window.__TEST__.files.set('notes/pasted.md', ''); }, formatted);
|
||||
await open('source.md');
|
||||
await writer();
|
||||
await page.locator('.cm-content').click();
|
||||
await page.keyboard.press('Control+a');
|
||||
await page.keyboard.press('Control+c');
|
||||
await open('pasted.md');
|
||||
await writer();
|
||||
for (let iteration = 0; iteration < 12; iteration++) {
|
||||
await page.locator('.cm-content').click();
|
||||
await page.keyboard.press('Control+a');
|
||||
await page.keyboard.press('Backspace');
|
||||
await expectWriter('');
|
||||
await page.keyboard.press('Control+v');
|
||||
await expectWriter(formatted);
|
||||
assert.equal(await page.locator('.live-writer .cm-editor').count(), 1, 'One mounted editor');
|
||||
await page.keyboard.press('Control+s');
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.files.get('notes/pasted.md').replace(/\r\n?/g, '\n')), formatted);
|
||||
if (iteration === 5) {
|
||||
await page.keyboard.press('Control+e');
|
||||
await page.locator('.source-editor .cm-content').waitFor();
|
||||
await page.keyboard.press('Control+e');
|
||||
await expectWriter(formatted);
|
||||
}
|
||||
await open('second.md');
|
||||
await writer();
|
||||
await page.getByRole('tab', { name: 'pasted.md', exact: true }).click();
|
||||
await expectWriter(formatted);
|
||||
}
|
||||
// Clipboard formats can use different line endings than the destination.
|
||||
for (const lineBreak of ['\n', '\r\n', '\r']) {
|
||||
await page.evaluate(({ text, lineBreak }) => {
|
||||
const view = window.__WRITER__;
|
||||
view.dispatch({ selection: { anchor: 0, head: view.state.doc.length } });
|
||||
const clipboardData = new DataTransfer();
|
||||
clipboardData.setData('text/plain', text.replace(/\n/g, lineBreak));
|
||||
view.contentDOM.dispatchEvent(new ClipboardEvent('paste', { bubbles: true, cancelable: true, clipboardData }));
|
||||
}, { text: formatted, lineBreak });
|
||||
await expectWriter(formatted);
|
||||
assert.equal(await page.evaluate(() => window.__WRITER__.state.doc.lines), formatted.split('\n').length);
|
||||
await page.keyboard.press('Control+s');
|
||||
// The saved file keeps one line break. The Writer text with that line break is the saved source.
|
||||
const synchronized = await page.evaluate(() => {
|
||||
const saved = window.__TEST__.files.get('notes/pasted.md');
|
||||
const lineBreak = saved.includes('\r\n') ? '\r\n' : '\n';
|
||||
return window.__WRITER__.state.doc.sliceString(0, undefined, lineBreak) === saved;
|
||||
});
|
||||
assert.equal(synchronized, true, 'Writer and saved source agree');
|
||||
}
|
||||
console.log('PASS: formatted Markdown copied across notes stays exact through 12 paste/delete cycles, saves, tab reopen, Source reopen, and LF/CRLF/CR clipboard replacement');
|
||||
});
|
||||
@@ -0,0 +1,56 @@
|
||||
// Front matter properties: first open, editing, undo, the saved selection, and both themes.
|
||||
import assert from "node:assert/strict";
|
||||
import { chooseView, mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("editor/properties", async ({ page }) => {
|
||||
await mockTauri(page, {
|
||||
commands: test => test.workspace({
|
||||
root: "C:\\smoke-workspace",
|
||||
files: {
|
||||
"notes/welcome.md": "---\ntitle: Welcome\n---\n\n# Working notes\n\nFirst paragraph.\n\n- [ ] A task\n\n[[second]]\n",
|
||||
"notes/second.md": "# Second note\n",
|
||||
"src/hello.py": "print('hello')\n",
|
||||
},
|
||||
}),
|
||||
});
|
||||
const output = await outputDir("editor/properties");
|
||||
await page.goto(smokeUrl);
|
||||
await page.getByText("smoke-workspace", { exact: true }).waitFor();
|
||||
await page.keyboard.press("Control+p");
|
||||
await page.getByRole("textbox", { name: "Find a file" }).fill("welcome.md");
|
||||
await page.getByRole("dialog").getByRole("button").filter({ hasText: "welcome.md" }).first().click();
|
||||
await page.getByRole('textbox', { name: 'Writing editor', exact: true }).waitFor();
|
||||
await page.locator('.md-properties').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 original = await page.evaluate(() => window.__CM__.state.sliceDoc());
|
||||
assert.equal(await page.evaluate(() => window.__CM__.state.selection.main.head), original.indexOf('\n\n') + 1);
|
||||
await page.locator('.md-properties summary').click();
|
||||
assert.equal(await page.locator('.md-properties').getAttribute('open'), '');
|
||||
assert.match(await page.locator('.md-properties pre').textContent(), /title: Welcome/);
|
||||
for (const mode of ['light', 'dark']) {
|
||||
await page.evaluate(async mode => {
|
||||
const { applyAppearance } = await import('/src/lib/theme/appearance.ts');
|
||||
applyAppearance({ theme: 'default', mode });
|
||||
}, mode);
|
||||
await page.setViewportSize({ width: 760, height: 900 });
|
||||
await page.screenshot({ path: `${output}/properties-${mode}-narrow.png` });
|
||||
}
|
||||
await page.evaluate(() => { window.__CM__.dispatch({ selection: { anchor: 11 } }); window.__CM__.focus(); });
|
||||
assert.equal(await page.locator('.md-properties').count(), 0);
|
||||
await page.keyboard.type('New ');
|
||||
assert.match(await page.evaluate(() => window.__CM__.state.sliceDoc()), /title: New Welcome/);
|
||||
await page.keyboard.press('Control+z');
|
||||
assert.equal(await page.evaluate(() => window.__CM__.state.sliceDoc()), original);
|
||||
await page.evaluate(() => window.__CM__.dispatch({ selection: { anchor: window.__CM__.state.doc.length } }));
|
||||
await page.locator('.md-properties').waitFor();
|
||||
await page.evaluate(() => { window.__CM__.dispatch({ selection: { anchor: 11 } }); window.__CM__.focus(); });
|
||||
await chooseView(page, 'Read');
|
||||
await page.locator('.reading .md-properties').waitFor();
|
||||
await chooseView(page, 'Write');
|
||||
await page.getByRole('textbox', { name: 'Writing editor', exact: true }).waitFor();
|
||||
assert.equal(await page.locator('.writer-preview .md-properties').count(), 0);
|
||||
console.log('Properties first-open, editing, undo, saved selection, and both themes passed.');
|
||||
});
|
||||
@@ -0,0 +1,145 @@
|
||||
// Scrolling in Write and Read through a large document with large tables, images, code blocks, and short lines keeps the text in place.
|
||||
import assert from "node:assert/strict";
|
||||
import { chooseView, mockTauri, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
const words = "lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua".split(" ");
|
||||
const text = (seed, count) => Array.from({ length: count }, (_, i) => words[(seed * 7 + i * 3) % words.length]).join(" ");
|
||||
|
||||
/** A short first heading holds the caret when the document opens. Short code lines and fences have another line height than prose. */
|
||||
function largeDocument() {
|
||||
const parts = ["# Large\n"];
|
||||
for (let section = 0; section < 10; section++) {
|
||||
parts.push(`## Section ${section}\n`, `Short line ${section}\n`, " \n");
|
||||
for (let p = 0; p < 5; p++) parts.push(`P${section}.${p} ${text(section + p, 30 + (p * 37) % 90)}\n`);
|
||||
const rows = Array.from({ length: 25 + (section * 17) % 50 }, (_, r) => `| T${section}R${r} | ${text(r, 2)} | ${text(section + r, 6 + (r * 11) % 50)} |`);
|
||||
parts.push(["| Row | Name | Description |", "| --- | --- | --- |", ...rows].join("\n") + "\n");
|
||||
if (section % 2 === 0) parts.push(`\n`);
|
||||
if (section % 3 === 0) parts.push("```python\nx = 1\ny = 2\n```\n");
|
||||
parts.push(`- item ${section} one\n- item ${section} two\n`);
|
||||
}
|
||||
return parts.join("\n");
|
||||
}
|
||||
|
||||
await runSmoke("editor/scrollStability", async ({ page }) => {
|
||||
await mockTauri(page, {
|
||||
state: { source: largeDocument() },
|
||||
commands: test => {
|
||||
const svg = (width, height) => btoa(`<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}"><rect width="100%" height="100%" fill="#336"/></svg>`);
|
||||
const files = { "notes/large.md": test.state.source };
|
||||
for (let section = 0; section < 10; section += 2) files[`notes/img${section}.svg`] = svg(1400, 700 + section * 60);
|
||||
const workspace = test.workspace({ root: "C:/smoke-workspace", files });
|
||||
return {
|
||||
...workspace,
|
||||
workspace_read_data_url: ({ rel }) => {
|
||||
if (!workspace.files.has(rel)) throw new Error("missing image");
|
||||
return "data:image/svg+xml;base64," + workspace.files.get(rel);
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
await page.setViewportSize({ width: 1440, height: 1000 });
|
||||
|
||||
/** Wheel over the view. After each tick lands, the text must be where the tick put it. Returns the ticks where the text moved by itself, and the document heights. */
|
||||
async function wheel(selector, delta, ticks) {
|
||||
const box = await page.locator(selector).boundingBox();
|
||||
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
|
||||
await page.evaluate(selector => {
|
||||
const scroller = document.querySelector(selector);
|
||||
const unique = /^s*(Td+Rd+|Pd+.d+|Short line d+|item d+ (?:one|two)|Section d+)/;
|
||||
const keyOf = element => unique.exec(element.textContent || "")?.[1] ?? "";
|
||||
const items = () => [...scroller.querySelectorAll(".cm-line, tr, .reading p, .reading h2, .reading li")];
|
||||
const frame = () => new Promise(resolve => requestAnimationFrame(resolve));
|
||||
const atEdge = () => scroller.scrollTop <= 0 || scroller.scrollTop + scroller.clientHeight >= scroller.scrollHeight - 2;
|
||||
let tracked = null;
|
||||
window.__scroll = {
|
||||
jumps: [], heights: [],
|
||||
before(delta) {
|
||||
const area = scroller.getBoundingClientRect(), margin = Math.abs(delta) + 60;
|
||||
const element = items().find(item => { const rect = item.getBoundingClientRect(); return rect.height > 0 && rect.top >= area.top + margin && rect.top <= area.bottom - margin && keyOf(item); });
|
||||
tracked = element ? { element, key: keyOf(element), top: element.getBoundingClientRect().top, delta, scrollTop: scroller.scrollTop } : null;
|
||||
},
|
||||
// A tick can land some frames later on a busy computer. Wait for it, then for the layout passes of the editor.
|
||||
async after() {
|
||||
for (let waited = 0; tracked && scroller.scrollTop === tracked.scrollTop && waited < 60; waited++) await frame();
|
||||
for (let settled = 0; settled < 3; settled++) await frame();
|
||||
this.heights.push(scroller.scrollHeight);
|
||||
if (atEdge()) return true;
|
||||
if (!tracked) return false;
|
||||
const element = tracked.element.isConnected ? tracked.element : items().find(item => keyOf(item) === tracked.key);
|
||||
if (!element) this.jumps.push(`${tracked.key} left the view`);
|
||||
else {
|
||||
const moved = Math.round(element.getBoundingClientRect().top - (tracked.top - tracked.delta));
|
||||
if (Math.abs(moved) > 4) this.jumps.push(`${tracked.key} moved ${moved}`);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
};
|
||||
}, selector);
|
||||
for (let tick = 0; tick < ticks; tick++) {
|
||||
await page.evaluate(delta => window.__scroll.before(delta), delta);
|
||||
await page.mouse.wheel(0, delta);
|
||||
if (await page.evaluate(() => window.__scroll.after()) && tick > 0) break;
|
||||
}
|
||||
return page.evaluate(() => ({ jumps: window.__scroll.jumps, heights: window.__scroll.heights }));
|
||||
}
|
||||
const jump = (selector, fraction) => page.evaluate(({ selector, fraction }) => { const scroller = document.querySelector(selector); scroller.scrollTop = scroller.scrollHeight * fraction; }, { selector, fraction });
|
||||
|
||||
await page.goto(smokeUrl);
|
||||
await page.getByText(/smoke-workspace/).first().waitFor();
|
||||
await page.keyboard.press("Control+p");
|
||||
await page.getByRole("textbox", { name: "Find a file" }).fill("large.md");
|
||||
await page.getByRole("dialog").getByRole("button").filter({ hasText: "large.md" }).first().click();
|
||||
await page.locator(".cm-content").waitFor();
|
||||
await page.waitForTimeout(400);
|
||||
|
||||
// Text that was not on screen yet: the heights are estimates until the first draw.
|
||||
await jump(".cm-scroller", .6);
|
||||
await page.waitForTimeout(300);
|
||||
const first = await wheel(".cm-scroller", -200, 120);
|
||||
assert.deepEqual(first.jumps, [], "Wheel up through new tables and images");
|
||||
const spread = heights => Math.max(...heights) - Math.min(...heights);
|
||||
// Line heights are estimates, but tables and images have their heights before the first draw.
|
||||
assert.ok(spread(first.heights) < Math.max(...first.heights) * .05, `The document keeps about its height at the first draw: ${Math.min(...first.heights)} to ${Math.max(...first.heights)}`);
|
||||
|
||||
// Text that was drawn before: images and tables come back with their heights.
|
||||
await jump(".cm-scroller", 0);
|
||||
await page.waitForTimeout(200);
|
||||
const down = await wheel(".cm-scroller", 400, 130);
|
||||
assert.deepEqual(down.jumps, [], "Wheel down to the end");
|
||||
const up = await wheel(".cm-scroller", -400, 130);
|
||||
assert.deepEqual(up.jumps, [], "Wheel up to the start");
|
||||
assert.ok(spread(up.heights) < 200, `The document keeps its height on the way back: ${Math.min(...up.heights)} to ${Math.max(...up.heights)}`);
|
||||
|
||||
// A short heading with the caret and a code block with the caret have another line height too.
|
||||
await page.evaluate(async () => {
|
||||
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
|
||||
const view = EditorView.findFromDOM(document.querySelector(".cm-content"));
|
||||
const heading = view.state.doc.toString().indexOf("## Section 3");
|
||||
view.dispatch({ selection: { anchor: heading + 3 }, scrollIntoView: true });
|
||||
});
|
||||
await page.waitForTimeout(300);
|
||||
const caret = await wheel(".cm-scroller", 300, 25);
|
||||
assert.deepEqual(caret.jumps, [], "Wheel down with the caret in a short heading");
|
||||
assert.ok(spread(caret.heights) < 200, `The document keeps its height with the caret in a short heading: ${Math.min(...caret.heights)} to ${Math.max(...caret.heights)}`);
|
||||
|
||||
// Images in Write keep their space before they load.
|
||||
const image = page.locator(".cm-content img[data-md-src]").first();
|
||||
await page.evaluate(async () => {
|
||||
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
|
||||
const view = EditorView.findFromDOM(document.querySelector(".cm-content"));
|
||||
view.scrollDOM.scrollTop = view.lineBlockAt(view.state.doc.toString().indexOf("![Picture 0]")).top;
|
||||
});
|
||||
await image.waitFor();
|
||||
assert.equal(await image.getAttribute("width"), "1400");
|
||||
assert.equal(await image.getAttribute("height"), "700");
|
||||
|
||||
// Read shows the same document without virtual lines.
|
||||
await chooseView(page, "Read");
|
||||
await page.locator(".md-page > .reading").waitFor();
|
||||
await page.waitForTimeout(300);
|
||||
await jump(".md-page", .6);
|
||||
await page.waitForTimeout(300);
|
||||
const reading = await wheel(".md-page", -300, 60);
|
||||
assert.deepEqual(reading.jumps, [], "Wheel up in Read");
|
||||
assert.equal(await page.locator(".md-page img[data-md-src]").first().getAttribute("height"), "700", "Images in Read keep their space before they load");
|
||||
}, { timeout: 30000 });
|
||||
@@ -0,0 +1,47 @@
|
||||
// Text selection uses --rs-selection in Writer (native and CodeMirror layers) and in Read view, in both themes.
|
||||
import assert from "node:assert/strict";
|
||||
import path from "node:path";
|
||||
import { chooseView, mockTauri, openPage, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
const name = "editor/selectionColor";
|
||||
await runSmoke(name, async ({ browser }) => {
|
||||
const output = await outputDir(name);
|
||||
for (const theme of ["light", "dark"]) {
|
||||
const page = await openPage(browser, { viewport: { width: 1100, height: 780 } });
|
||||
await mockTauri(page, {
|
||||
commands: test => ({
|
||||
...test.workspace({ root: "C:\\selection-color", files: { "sample.md": "# Selection sample\n\nThe same text color applies to each editor.\n" } }),
|
||||
plugins_snapshot: () => ({ root: "C:/plugins", plugins: [] }),
|
||||
}),
|
||||
});
|
||||
await page.goto(smokeUrl);
|
||||
await page.getByText("selection-color", { exact: true }).waitFor();
|
||||
await page.evaluate(async theme => (await import("/src/lib/theme/appearance.ts")).saveAppearance({ theme: "default", mode: theme }), theme);
|
||||
await page.keyboard.press("Control+p");
|
||||
await page.getByRole("textbox", { name: "Find a file" }).fill("sample.md");
|
||||
await page.getByRole("textbox", { name: "Find a file" }).press("Enter");
|
||||
const writer = page.getByRole("textbox", { name: "Writing editor", exact: true });
|
||||
await writer.waitFor();
|
||||
await writer.click();
|
||||
await page.keyboard.press("Control+a");
|
||||
const colors = await writer.evaluate(node => {
|
||||
const probe = document.createElement("span");
|
||||
probe.style.backgroundColor = "var(--rs-selection)";
|
||||
node.append(probe);
|
||||
const expected = getComputedStyle(probe).backgroundColor;
|
||||
probe.remove();
|
||||
return { expected, native: getComputedStyle(node, "::selection").backgroundColor,
|
||||
layer: getComputedStyle(document.querySelector(".cm-selectionBackground")).backgroundColor };
|
||||
});
|
||||
assert.equal(colors.native, colors.expected);
|
||||
assert.equal(colors.layer, colors.expected);
|
||||
await page.screenshot({ path: path.join(output, `${theme}-writer-selection.png`) });
|
||||
await chooseView(page, "Read");
|
||||
const reader = page.locator(".reading");
|
||||
await reader.waitFor();
|
||||
assert.equal(await reader.evaluate(node => getComputedStyle(node, "::selection").backgroundColor), colors.expected);
|
||||
assert.deepEqual(page.errors, []);
|
||||
await page.close();
|
||||
console.log(`PASS: ${theme} Writer and Read view selection`);
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,133 @@
|
||||
// Editor menu surfaces: Writer, spelling, Source, and code menus share the file menu styles; and the code tint match in both themes.
|
||||
import assert from "node:assert/strict";
|
||||
import { chooseView, mockTauri, outputDir, runSmoke, showSavedImage, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("editor/surfaces", async ({ page }) => {
|
||||
await mockTauri(page, {
|
||||
commands: test => {
|
||||
const note = name => `# ${name}\n\nOriginal text.\n\n\`\`\`js\nconst answer = 42;\n\`\`\`\n\n| Name | Value |\n| --- | --- |\n| Alpha | One |\n`;
|
||||
return {
|
||||
...test.workspace({
|
||||
root: "C:\\tab-menu-workspace",
|
||||
files: { ...Object.fromEntries(["a.md", "b.md", "c.md", "d.md"].map(name => [name, note(name)])), "sample.txt": "const answer = 42;\n" },
|
||||
folders: ["notes"],
|
||||
}),
|
||||
spelling_menu_install: () => null,
|
||||
spelling_suggestions: ({ word }) => ({ language: "en-US", words: ["Corrected"], misspelled: word === "Original" }),
|
||||
};
|
||||
},
|
||||
});
|
||||
const menu = name => page.getByRole('menu', { name, exact: true });
|
||||
const item = name => page.getByRole('menuitem', { name, exact: true });
|
||||
const output = await outputDir("editor/surfaces");
|
||||
const report = [];
|
||||
const dismiss = async () => { await page.keyboard.press('Escape'); await page.locator('.rs-menu').waitFor({ state: 'detached' }); };
|
||||
const styles = panel => panel.evaluate(node => {
|
||||
const row = node.querySelector(':scope > button');
|
||||
const a = getComputedStyle(node), b = getComputedStyle(row);
|
||||
return [a.backgroundColor, a.borderRadius, a.padding, b.minHeight, b.padding, b.font];
|
||||
});
|
||||
await page.goto(smokeUrl);
|
||||
await page.locator('[data-tree-rel="a.md"]').click();
|
||||
await page.locator('.cm-content').waitFor();
|
||||
for (const theme of ['dark', 'light']) {
|
||||
await page.setViewportSize({ width: 1440, height: 1000 });
|
||||
await page.evaluate(async mode => {
|
||||
const { saveAppearance } = await import('/src/lib/theme/appearance.ts');
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = 800; canvas.height = 600;
|
||||
const c = canvas.getContext('2d');
|
||||
const g = c.createLinearGradient(0, 0, 800, 600);
|
||||
g.addColorStop(0, '#628ba8'); g.addColorStop(1, '#b47796');
|
||||
c.fillStyle = g; c.fillRect(0, 0, 800, 600);
|
||||
saveAppearance({ theme: 'default', mode, newTabBackground: { image: canvas.toDataURL(), overlay: .15, position: 'center', size: 'cover' } });
|
||||
}, theme);
|
||||
await showSavedImage(page);
|
||||
await page.locator('[data-tree-rel="a.md"]').click({ button: 'right' });
|
||||
const reference = await styles(menu('File actions'));
|
||||
await dismiss();
|
||||
const text = page.getByText('Original text.', { exact: true });
|
||||
await text.click({ button: 'right', position: { x: 20, y: 8 } });
|
||||
const writer = menu('Markdown text actions');
|
||||
assert.deepEqual(await styles(writer), reference);
|
||||
for (const name of ['Add link', 'Add external link Ctrl+K', 'Format', 'Paragraph', 'Insert', 'Paste Ctrl+V', 'Select all Ctrl+A']) assert.equal(await item(name).count(), 1);
|
||||
await item('Corrected').waitFor();
|
||||
assert.equal(await item('Spelling').count(), 0, 'Corrections appear directly in the main menu');
|
||||
assert.equal(await writer.locator(':scope > button').first().textContent(), 'Corrected');
|
||||
await page.screenshot({ path: `${output}/writer-menu-${theme}.png` });
|
||||
await item('Corrected').focus(); await page.keyboard.press('Enter');
|
||||
await page.getByText('Corrected text.', { exact: true }).waitFor();
|
||||
await page.keyboard.press('Control+z');
|
||||
await text.waitFor();
|
||||
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 text.click({ button: 'right', position: { x: 20, y: 8 } });
|
||||
await item('Corrected').waitFor();
|
||||
await page.keyboard.press('Home');
|
||||
assert.equal(await item('Corrected').evaluate(node => node === document.activeElement), true);
|
||||
const spellingBounds = await writer.boundingBox();
|
||||
assert.ok(spellingBounds.x >= 8 && spellingBounds.x + spellingBounds.width <= 552);
|
||||
await page.screenshot({ path: `${output}/spelling-narrow-${theme}.png` });
|
||||
await page.keyboard.press('Enter');
|
||||
await page.getByText('Corrected text.', { exact: true }).waitFor();
|
||||
await page.keyboard.press('Control+z');
|
||||
await text.waitFor();
|
||||
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('.cm-content').click({ button: 'right', position: { x: 600, y: 150 } });
|
||||
assert.deepEqual(await styles(writer), reference, 'Blank space uses the same actions');
|
||||
await item('Format').focus(); await page.keyboard.press('ArrowRight');
|
||||
await item('Bold Ctrl+B').click();
|
||||
await page.locator('.cm-content').click({ button: 'right', position: { x: 600, y: 150 } });
|
||||
await page.getByRole('menuitem', { name: 'Undo Ctrl+Z', exact: true }).click();
|
||||
assert.equal(await page.locator('.cm-content').textContent().then(s => s.includes('**')), false, 'Undo reverses the menu edit');
|
||||
const tint = await page.locator('.writer-code-line').first().evaluate(node => getComputedStyle(node).backgroundColor);
|
||||
assert.ok(tint.includes('/ 0.82') || /rgba\(.+, 0\.82\)/.test(tint), `Writer code tint: ${tint}`);
|
||||
await page.screenshot({ path: `${output}/writer-code-${theme}.png` });
|
||||
await chooseView(page, 'Read');
|
||||
const readingTint = await page.locator('pre.md-code').evaluate(node => getComputedStyle(node).backgroundColor);
|
||||
assert.equal(readingTint, tint, 'Reader and Writer use the same code tint');
|
||||
await page.screenshot({ path: `${output}/reader-code-${theme}.png` });
|
||||
await chooseView(page, 'Source');
|
||||
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 Source retains the same menu');
|
||||
await dismiss();
|
||||
await page.locator('[data-tree-rel="sample.txt"]').click();
|
||||
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 Source uses the host menu');
|
||||
// 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 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('.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: '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 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 chooseView(page, 'Write');
|
||||
report.push({ theme, passed: ['word and blank menu parity', 'spelling correction and undo', 'Writer/Source 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 });
|
||||
@@ -0,0 +1,101 @@
|
||||
// Note templates and task lines: template creation, filename focus, task entry, checkbox toggles, lone hyphens, and Setext headings.
|
||||
import assert from "node:assert/strict";
|
||||
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("editor/templatesAndTasks", async ({ page }) => {
|
||||
await mockTauri(page, {
|
||||
commands: test => {
|
||||
const workspace = test.workspace({
|
||||
root: "C:\\smoke-workspace",
|
||||
files: {
|
||||
"notes/welcome.md": "---\ntitle: Welcome\n---\n\n# Working notes\n\nFirst paragraph.\n\n- [ ] A task\n\n[[second]]\n",
|
||||
"notes/second.md": "# Second note\n",
|
||||
"src/hello.py": "print('hello')\n",
|
||||
},
|
||||
writeEvents: true,
|
||||
});
|
||||
test.files = workspace.files;
|
||||
return {
|
||||
...workspace,
|
||||
// Saves send the last saved text. Reject a save when the file changed, as the backend does.
|
||||
workspace_write: args => {
|
||||
if (args.expected !== undefined && workspace.files.get(args.rel) !== args.expected) throw new Error("Save blocked: file changed on disk");
|
||||
return workspace.workspace_write(args);
|
||||
},
|
||||
// The tree hides the root .runestone folder; its templates folder stays listable.
|
||||
workspace_list: args => workspace.workspace_list(args).filter(entry => args.rel || entry.rel_path !== ".runestone"),
|
||||
};
|
||||
},
|
||||
});
|
||||
const output = await outputDir("editor/templatesAndTasks");
|
||||
await page.goto(smokeUrl);
|
||||
await page.getByText('smoke-workspace', { exact: true }).waitFor();
|
||||
// Save the empty task lines from the reported template, then create through
|
||||
// the normal note action so the filename receives the initial focus.
|
||||
await page.evaluate(async () => {
|
||||
const { saveNoteTemplate } = await import('/src/lib/workspace/templates.ts');
|
||||
await saveNoteTemplate('To Do', '- [ ] \n'.repeat(10));
|
||||
});
|
||||
await page.getByRole('button', { name: 'New tab (Ctrl+T)', exact: true }).click();
|
||||
await page.getByRole('button', { name: 'New note', exact: true }).last().click();
|
||||
await page.getByRole('menuitem', { name: 'To Do', exact: true }).click();
|
||||
const title = page.getByRole('textbox', { name: 'Note filename', exact: true });
|
||||
await title.waitFor();
|
||||
await page.waitForFunction(() => document.activeElement?.getAttribute('aria-label') === 'Note filename');
|
||||
await page.evaluate(async () => {
|
||||
const { EditorView } = await import('/node_modules/@codemirror/view/dist/index.js');
|
||||
window.__CM__ = EditorView.findFromDOM(document.querySelector('.cm-content'));
|
||||
});
|
||||
const count = () => page.locator('.writer-checkbox').count();
|
||||
const expectCount = async expected => {
|
||||
await page.waitForFunction(expected => document.querySelectorAll('.writer-checkbox').length === expected, expected);
|
||||
assert.equal(await count(), expected);
|
||||
};
|
||||
const setSource = source => page.evaluate(source => {
|
||||
window.__CM__.dispatch({ changes: { from: 0, to: window.__CM__.state.doc.length, insert: source }, selection: { anchor: source.length } });
|
||||
window.__CM__.focus();
|
||||
}, source);
|
||||
const plain = 'Some generic mobs or factions,\n-';
|
||||
for (const mode of ['dark', 'light']) {
|
||||
await page.evaluate(async mode => (await import('/src/lib/theme/appearance.ts')).saveAppearance({ theme: 'default', mode }), mode);
|
||||
for (const width of [1440, 600]) {
|
||||
await page.setViewportSize({ width, height: width === 600 ? 760 : 1000 });
|
||||
// The side panes give way in a narrow window and come back in a wide one (src/lib/layout/Workbench.svelte).
|
||||
await page.waitForFunction(width => !!document.querySelector('aside.left') === width >= 800, width);
|
||||
if (!(await title.isVisible())) await page.getByRole('button', { name: 'Rename note', exact: true }).click();
|
||||
await title.focus();
|
||||
await expectCount(10);
|
||||
await page.screenshot({ path: `${output}/${mode}-${width}-template-title.png` });
|
||||
await page.keyboard.press('Escape');
|
||||
await page.evaluate(() => {
|
||||
const view = window.__CM__;
|
||||
view.dispatch({ selection: { anchor: 0 } }); view.focus();
|
||||
});
|
||||
await expectCount(9);
|
||||
await page.keyboard.press('End');
|
||||
await page.keyboard.type('First task');
|
||||
await expectCount(10);
|
||||
await page.locator('.writer-checkbox').first().click();
|
||||
assert.match(await page.evaluate(() => window.__CM__.state.sliceDoc()), /^- \[x\] First task/);
|
||||
await page.screenshot({ path: `${output}/${mode}-${width}-template-edit.png` });
|
||||
|
||||
await setSource(plain);
|
||||
assert.equal(await page.locator('.writer-h2').count(), 0, 'A lone hyphen must not enlarge preceding prose');
|
||||
await page.screenshot({ path: `${output}/${mode}-${width}-single-hyphen.png` });
|
||||
await page.keyboard.type(' Item');
|
||||
assert.equal(await page.locator('.writer-h2').count(), 0, 'The hyphen continues into a list');
|
||||
assert.equal(await page.evaluate(() => window.__CM__.state.sliceDoc()), plain + ' Item');
|
||||
await setSource(plain + '-');
|
||||
assert.equal(await page.locator('.writer-h2').count(), 1, 'Two hyphens retain Setext heading support');
|
||||
await setSource('A normal heading\n===\n');
|
||||
assert.equal(await page.locator('.writer-h1').count(), 1);
|
||||
// Restore the template for the next theme and size without an active body caret.
|
||||
await setSource('- [ ] \n'.repeat(10));
|
||||
await page.getByRole('button', { name: 'Rename note', exact: true }).click();
|
||||
if (width === 600) {
|
||||
await page.setViewportSize({ width: 1440, height: 1000 });
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log('PASS: template creation, filename focus, keyboard task entry, checkbox toggle, lone hyphen, list continuation, and Setext headings in both themes and narrow layouts.');
|
||||
});
|
||||
@@ -0,0 +1,125 @@
|
||||
// Undo history survives tab switches, window focus, Source edits, and table cell edits.
|
||||
import assert from "node:assert/strict";
|
||||
import { mockTauri, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("editor/undoHistory", async ({ page }) => {
|
||||
await mockTauri(page, {
|
||||
commands: test => {
|
||||
const workspace = test.workspace({
|
||||
root: "C:\\smoke-workspace",
|
||||
files: {
|
||||
"notes/welcome.md": "---\ntitle: Welcome\n---\n\n# Working notes\n\nFirst paragraph.\n\n- [ ] A task\n\n[[second]]\n",
|
||||
"notes/second.md": "# Second note\n",
|
||||
"src/hello.py": "print('hello')\n",
|
||||
},
|
||||
writeEvents: true,
|
||||
});
|
||||
test.files = workspace.files;
|
||||
return {
|
||||
...workspace,
|
||||
// Saves send the last saved text. Reject a save when the file changed, as the backend does.
|
||||
workspace_write: args => {
|
||||
if (args.expected !== undefined && workspace.files.get(args.rel) !== args.expected) throw new Error("Save blocked: file changed on disk");
|
||||
return workspace.workspace_write(args);
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
async function open(name) {
|
||||
await page.keyboard.press('Control+p');
|
||||
await page.getByRole('textbox', { name: 'Find a file' }).fill(name);
|
||||
await page.getByRole('dialog').getByRole('button').filter({ hasText: name }).first().click();
|
||||
}
|
||||
async function writer() {
|
||||
await page.locator('.cm-content').waitFor();
|
||||
return page.evaluate(async () => {
|
||||
const { EditorView } = await import('/node_modules/@codemirror/view/dist/index.js');
|
||||
window.__WRITER__ = EditorView.findFromDOM(document.querySelector('.cm-content'));
|
||||
return window.__WRITER__.state.sliceDoc();
|
||||
});
|
||||
}
|
||||
async function expectWriter(expected) {
|
||||
await writer();
|
||||
try { await page.waitForFunction(text => window.__WRITER__.state.sliceDoc() === text, expected); } catch (error) { console.log({ expected, actual: await writer(), errors: page.errors }); throw error; }
|
||||
}
|
||||
await page.goto(smokeUrl);
|
||||
await page.getByText('smoke-workspace', { exact: true }).waitFor();
|
||||
await open('welcome.md');
|
||||
const original = await writer();
|
||||
await page.locator('.cm-content').click();
|
||||
await page.keyboard.press('Control+End');
|
||||
await page.keyboard.type(' first edit');
|
||||
await expectWriter(original + ' first edit');
|
||||
await page.keyboard.press('Control+s');
|
||||
await open('second.md');
|
||||
await writer();
|
||||
await page.getByRole('tab', { name: 'welcome.md', exact: true }).click();
|
||||
await expectWriter(original + ' first edit');
|
||||
await page.keyboard.press('Control+z');
|
||||
await expectWriter(original);
|
||||
await page.keyboard.press('Control+y');
|
||||
await expectWriter(original + ' first edit');
|
||||
console.log('PASS: saved Writer edit survives tab switch with undo and redo');
|
||||
await page.evaluate(() => window.dispatchEvent(new Event('focus')));
|
||||
await page.keyboard.press('Control+z');
|
||||
await expectWriter(original);
|
||||
await page.keyboard.press('Control+y');
|
||||
await expectWriter(original + ' first edit');
|
||||
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('.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.length } });
|
||||
view.focus();
|
||||
window.__IDE__ = view;
|
||||
});
|
||||
await page.keyboard.type(' second edit');
|
||||
assert.equal(await page.evaluate(() => window.__IDE__.dom.isConnected), true, 'Typing keeps the same Source 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();
|
||||
// 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');
|
||||
await expectWriter(original);
|
||||
await page.keyboard.press('Control+y');
|
||||
await expectWriter(original + ' first edit');
|
||||
await page.keyboard.press('Control+y');
|
||||
await expectWriter(original + ' first edit second edit');
|
||||
console.log('PASS: Writer undo includes edits from Source mode');
|
||||
const tableSource = '# Table\n\n| A | B |\n| --- | --- |\n| One | Two |\n\nTail.\n';
|
||||
await page.evaluate(source => {
|
||||
window.__TEST__.files.set('table.md', source);
|
||||
window.__TEST__.emit('workspace-event', { root: window.__TEST__.root, kind: 'create', paths: ['table.md'] });
|
||||
}, tableSource);
|
||||
await open('table.md');
|
||||
await writer();
|
||||
const cells = page.locator('.writer-table tbody td');
|
||||
await cells.nth(0).click();
|
||||
await page.keyboard.press('Control+a');
|
||||
await page.keyboard.type('Alpha');
|
||||
await cells.nth(1).click();
|
||||
await page.keyboard.press('Control+a');
|
||||
await page.keyboard.type('Beta');
|
||||
await page.keyboard.press('Escape');
|
||||
const editedTable = await writer();
|
||||
assert.ok(editedTable.includes('Alpha') && editedTable.includes('Beta'));
|
||||
await page.getByRole('tab', { name: 'welcome.md', exact: true }).click();
|
||||
await writer();
|
||||
await page.getByRole('tab', { name: 'table.md', exact: true }).click();
|
||||
await writer();
|
||||
await page.keyboard.press('Control+z');
|
||||
await expectWriter(editedTable.replace('Beta', 'Two'));
|
||||
await page.keyboard.press('Control+z');
|
||||
await expectWriter(tableSource);
|
||||
await page.keyboard.press('Control+y');
|
||||
await expectWriter(editedTable.replace('Beta', 'Two'));
|
||||
await page.keyboard.press('Control+y');
|
||||
await expectWriter(editedTable);
|
||||
console.log('PASS: table cell typing stays grouped per cell across tab switches');
|
||||
});
|
||||
Reference in New Issue
Block a user