Phase 4b. DocumentEditor.svelte replaces LiveWriter.svelte and the Monaco EditorHost.svelte. Each open document has one CodeMirror state. Write and Source are two compartment configurations of it, so they share the undo history. editorStates.ts keeps the state while the tab stays open. The Monaco model, the diff bridge, its timers, and sessions.ts are gone. - Source: syntax colors from the theme tokens, lazy language packages, line numbers, folding, and the current line in IDE, wrapped lines in Writing, several carets, and bracket matching and closing. - Lists (card 088e778b): Tab nests a list item and Shift+Tab moves it up, in Write and Source. Both renumber the list. The source keeps "1.". Write and Read show numbers, letters, then Roman numerals. - Indent (card 696c30ce): a fixed 4 spaces in Write and Source. - The code menu uses CodeMirror commands. The command palette item and the Monaco styles, search, theme, and workers are removed. - @codemirror/legacy-modes is pinned to 6.5.4. Version 6.5.5 uses parser types that do not match @codemirror/language 6.12. - 26 smoke tests use CodeMirror instead of Monaco. New tests: editor/listNesting and the markdownLists unit tests. - Docs: development, UI design, plugin host, user guide, and UI-040. pnpm check, pnpm test (341 of 341), and pnpm build pass. The full smoke suite passes, except one template test that passed on retry.
166 lines
11 KiB
JavaScript
166 lines
11 KiB
JavaScript
// Built-in palettes: modes, light-only Sakura, migration, persistence, typography, cross-window sync, source editor updates, and narrow settings.
|
|
import assert from "node:assert/strict";
|
|
import path from "node:path";
|
|
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
|
|
|
await runSmoke("appearance/palettes", async ({ browser }) => {
|
|
const output = await outputDir("appearance/palettes");
|
|
const context = await browser.newContext({ viewport: { width: 1100, height: 780 } });
|
|
await mockTauri(context, {
|
|
commands: test => ({
|
|
...test.workspace({
|
|
root: "C:\\appearance-smoke",
|
|
files: Object.fromEntries(Array.from({ length: 12 }, (_, index) => [`theme-${index}.py`, `# Theme sample ${index}\ndef sample(parameter):\n return parameter\nname = "RuneStone"\nprint(name, 42)\n`])),
|
|
}),
|
|
plugins_snapshot: () => ({ root: "C:/appearance-smoke-plugins", plugins: [] }),
|
|
"plugin:window|is_maximized": () => false,
|
|
}),
|
|
});
|
|
const main = await openPage(context);
|
|
const settings = await openPage(context);
|
|
const secondSettings = await openPage(context);
|
|
const pages = [main, settings, secondSettings];
|
|
try {
|
|
await main.goto(smokeUrl);
|
|
await main.getByText("appearance-smoke", { exact: true }).waitFor();
|
|
async function openCode(index) {
|
|
await main.keyboard.press("Control+p");
|
|
await main.getByRole("textbox", { name: "Find a file" }).fill(`theme-${index}.py`);
|
|
await main.getByRole("dialog").getByRole("button").filter({ hasText: `theme-${index}.py` }).first().waitFor();
|
|
await main.getByRole("textbox", { name: "Find a file" }).press("Enter");
|
|
await main.locator(".source-editor .cm-content").waitFor();
|
|
await main.waitForFunction(file => document.querySelector(".editor .breadcrumb")?.textContent.endsWith(file)
|
|
&& document.querySelector(".source-editor .cm-content")?.dataset.language === "python", `theme-${index}.py`);
|
|
await main.locator(".source-editor .cm-line").filter({ hasText: `Theme sample ${index}` }).waitFor();
|
|
}
|
|
async function editorIds() {
|
|
// Mark each mounted editor once. A new editor has no mark, so it gets a new identifier.
|
|
return main.evaluate(() => [...document.querySelectorAll(".source-editor .cm-editor")]
|
|
.map(node => node.dataset.smokeId ||= String(window.__editorSerial = (window.__editorSerial || 0) + 1)));
|
|
}
|
|
// Wait until "RuneStone", "def", and "42" have three distinct syntax colors.
|
|
async function waitForSyntax() {
|
|
await main.waitForFunction(() => {
|
|
const spans = [...document.querySelectorAll(".source-editor .cm-line span")];
|
|
const colors = ["RuneStone", "def", "42"].map(text => {
|
|
const span = spans.find(node => !node.children.length && node.textContent.includes(text));
|
|
return span ? getComputedStyle(span).color : null;
|
|
});
|
|
return colors.every(Boolean) && new Set(colors).size === 3;
|
|
});
|
|
}
|
|
const themeName = (theme, mode) => theme === "sakura" ? "Sakura" : `${({ default: "RuneStone", claude: "Claude" })[theme]} ${mode === "light" ? "Light" : "Dark"}`;
|
|
const picker = (page, name) => page.locator(".picker").filter({ has: page.locator("svg") }).and(page.getByRole("button", { name, exact: true }));
|
|
async function choose(page, theme, mode) {
|
|
await picker(page, "Color theme").click();
|
|
await page.getByRole("menuitemradio", { name: themeName(theme, mode), exact: true }).click();
|
|
}
|
|
async function openAppearance(page) {
|
|
await page.goto(`${smokeUrl}/?settingsWindow=true`);
|
|
await page.getByRole("button", { name: "Appearance", exact: true }).click();
|
|
await picker(page, "Color theme").waitFor();
|
|
}
|
|
await openCode(0);
|
|
await openAppearance(settings);
|
|
await openAppearance(secondSettings);
|
|
async function expectAppearance(theme, mode) {
|
|
for (const page of [settings, secondSettings, main]) {
|
|
await page.waitForFunction(({ theme, mode }) => document.documentElement.dataset.palette === theme && document.documentElement.dataset.theme === mode, { theme, mode });
|
|
assert.equal(await page.evaluate(() => getComputedStyle(document.documentElement).colorScheme), mode);
|
|
}
|
|
assert.equal((await picker(secondSettings, "Color theme").textContent()).trim(), themeName(theme, mode));
|
|
await main.waitForFunction(() => {
|
|
const root = document.documentElement;
|
|
const probe = document.createElement("i");
|
|
probe.style.backgroundColor = getComputedStyle(root).getPropertyValue("--rs-workarea-editor-bg");
|
|
document.body.append(probe);
|
|
const expected = getComputedStyle(probe).backgroundColor;
|
|
probe.remove();
|
|
const surfaces = [...document.querySelectorAll(".source-editor .cm-editor")];
|
|
const workarea = document.querySelector(".editor > .body");
|
|
return surfaces.length > 0 && surfaces.every(element => getComputedStyle(element).backgroundColor === "rgba(0, 0, 0, 0)")
|
|
&& workarea && getComputedStyle(workarea).backgroundColor === expected;
|
|
});
|
|
return settings.evaluate(() => getComputedStyle(document.documentElement).getPropertyValue("--rs-bg").trim());
|
|
}
|
|
let nextCode = 1;
|
|
const backgrounds = new Set();
|
|
|
|
for (const theme of ["default", "claude", "sakura"]) {
|
|
for (const mode of theme === "sakura" ? ["light"] : ["light", "dark"]) {
|
|
const before = await editorIds();
|
|
await choose(settings, theme, mode);
|
|
backgrounds.add(await expectAppearance(theme, mode));
|
|
assert.deepEqual(await editorIds(), before, "Existing source editors keep their identity when a theme changes");
|
|
await openCode(nextCode++);
|
|
assert.notDeepEqual(await editorIds(), before, "A new file creates a new source editor");
|
|
await expectAppearance(theme, mode);
|
|
await waitForSyntax();
|
|
assert.deepEqual(await settings.evaluate(() => window.__TEST__.settings("appearance")), { theme, mode });
|
|
await settings.screenshot({ path: path.join(output, `appearance-${theme}-${mode}.png`) });
|
|
await main.screenshot({ path: path.join(output, `appearance-editor-${theme}-${mode}.png`) });
|
|
if (theme === "sakura") {
|
|
const keywordColor = await main.locator(".source-editor .cm-line span").evaluateAll(spans => {
|
|
const keyword = spans.find(span => !span.children.length && span.textContent.trim() === "def");
|
|
return keyword ? getComputedStyle(keyword).color : null;
|
|
});
|
|
assert.equal(keywordColor, "rgb(152, 85, 108)", "Sakura keywords use Plum Wine");
|
|
}
|
|
const typography = await settings.evaluate(() => ({
|
|
body: getComputedStyle(document.body).fontFamily,
|
|
heading: getComputedStyle(document.querySelector("h2")).fontFamily,
|
|
prose: getComputedStyle(document.documentElement).getPropertyValue("--rs-font-prose").trim(),
|
|
}));
|
|
if (theme === "claude") {
|
|
assert.match(typography.body, /Lora.*Georgia/);
|
|
assert.match(typography.prose, /Lora.*Georgia/);
|
|
assert.match(typography.heading, /Poppins.*Arial/);
|
|
assert.equal(await settings.evaluate(() => getComputedStyle(document.documentElement).getPropertyValue("--rs-accent").trim()), "#d97757");
|
|
} else assert.doesNotMatch(typography.body, /Lora|Georgia/);
|
|
console.log(`PASS: ${theme} ${mode}, saved state, cross-window selection, existing and new source editors`);
|
|
}
|
|
}
|
|
assert.equal(backgrounds.size, 5, "All supported combinations have distinct backgrounds");
|
|
await picker(settings, "Color theme").click();
|
|
assert.deepEqual(await settings.getByRole("menuitemradio").allTextContents(), ["RuneStone Light", "RuneStone Dark", "Claude Light", "Claude Dark", "Sakura", "Harvest Moon", "Crimson Pilot", "Silver Serpent"]);
|
|
await settings.keyboard.press("Escape");
|
|
assert.equal(await picker(settings, "Appearance").count(), 0);
|
|
assert.equal(await picker(secondSettings, "Appearance").count(), 0);
|
|
const sakura = await settings.evaluate(() => {
|
|
const css = getComputedStyle(document.documentElement);
|
|
return Object.fromEntries(["bg", "border", "selection", "bg-active", "syntax-parameter", "syntax-keyword", "syntax-local", "syntax-static", "syntax-instance", "syntax-global"].map(key => [key, css.getPropertyValue(`--rs-${key}`).trim()]));
|
|
});
|
|
// The applied selection color caps its alpha at a6 so text backgrounds show through (src/lib/theme/appearance.ts:197-203).
|
|
assert.deepEqual(sakura, { bg: "#fefcfc", border: "#f8dbe6", selection: "#ffc9dca6", "bg-active": "#dbeacb", "syntax-parameter": "#cb6b91", "syntax-keyword": "#98556c", "syntax-local": "#618c71", "syntax-static": "#69a2bd", "syntax-instance": "#607fa9", "syntax-global": "#687788" });
|
|
for (const [theme, savedMode, expectedTheme, mode] of [
|
|
["gpt", "light", "default", "light"],
|
|
["terminal", "dark", "default", "dark"],
|
|
["sakura", "dark", "sakura", "light"],
|
|
]) {
|
|
await settings.evaluate(value => window.__TEST__.writeSettings("appearance", value), { theme, mode: savedMode });
|
|
await settings.reload();
|
|
await settings.getByRole("button", { name: "Appearance", exact: true }).click();
|
|
await expectAppearance(expectedTheme, mode);
|
|
assert.deepEqual(await settings.evaluate(() => window.__TEST__.settings("appearance")), { theme: expectedTheme, mode });
|
|
console.log(`PASS: saved ${theme} ${savedMode} migrates to ${expectedTheme} ${mode}`);
|
|
}
|
|
for (const [theme, mode] of [["default", "dark"], ["claude", "light"], ["claude", "dark"], ["sakura", "light"]]) {
|
|
await settings.setViewportSize({ width: 1100, height: 780 });
|
|
await choose(settings, theme, mode);
|
|
await expectAppearance(theme, mode);
|
|
await settings.setViewportSize({ width: 360, height: 480 });
|
|
assert(await settings.evaluate(() => document.documentElement.scrollWidth <= innerWidth), "Narrow settings do not overflow the viewport");
|
|
assert(await settings.locator("dialog .content").evaluate(node => node.scrollWidth <= node.clientWidth), "Appearance controls do not overflow the content area");
|
|
const control = picker(settings, "Color theme");
|
|
await control.scrollIntoViewIfNeeded();
|
|
const bounds = await control.boundingBox();
|
|
assert(bounds.x >= 0 && bounds.x + bounds.width <= 360 && bounds.height >= 28, "Color theme remains reachable at 360px");
|
|
await settings.screenshot({ path: path.join(output, `appearance-${theme}-${mode}-360.png`) });
|
|
}
|
|
assert.deepEqual(pages.flatMap(page => page.errors), []);
|
|
} catch (error) {
|
|
for (const [index, page] of pages.entries()) await page.screenshot({ path: path.join(output, `appearance-failure-${index}.png`) }).catch(() => {});
|
|
throw error;
|
|
}
|
|
});
|