A browser tab shows the download size, Download the engine, Install from file, and Open in default browser until the engine can start. It shows progress, Cancel, the cause of a failure, and Retry, and then opens the page. Settings -> Browser shows the engine state and Remove engine. Web links open in the system browser until the engine is installed. Open link in app browser always opens a browser tab.
130 lines
8.9 KiB
JavaScript
130 lines
8.9 KiB
JavaScript
// 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 });
|