Files
RuneStone/tests/smoke/tabs/scroll.smoke.mjs
T
Knotty Wyvern 724402729e Replace Monaco with one CodeMirror editor and nest list items with Tab
Phase 4b. DocumentEditor.svelte replaces LiveWriter.svelte and the Monaco
EditorHost.svelte. Each open document has one CodeMirror state. Write and
Source are two compartment configurations of it, so they share the undo
history. editorStates.ts keeps the state while the tab stays open. The
Monaco model, the diff bridge, its timers, and sessions.ts are gone.

- Source: syntax colors from the theme tokens, lazy language packages,
  line numbers, folding, and the current line in IDE, wrapped lines in
  Writing, several carets, and bracket matching and closing.
- Lists (card 088e778b): Tab nests a list item and Shift+Tab moves it
  up, in Write and Source. Both renumber the list. The source keeps
  "1.". Write and Read show numbers, letters, then Roman numerals.
- Indent (card 696c30ce): a fixed 4 spaces in Write and Source.
- The code menu uses CodeMirror commands. The command palette item and
  the Monaco styles, search, theme, and workers are removed.
- @codemirror/legacy-modes is pinned to 6.5.4. Version 6.5.5 uses
  parser types that do not match @codemirror/language 6.12.
- 26 smoke tests use CodeMirror instead of Monaco. New tests:
  editor/listNesting and the markdownLists unit tests.
- Docs: development, UI design, plugin host, user guide, and UI-040.

pnpm check, pnpm test (341 of 341), and pnpm build pass. The full smoke
suite passes, except one template test that passed on retry.
2026-10-28 10:48:44 -07:00

84 lines
4.0 KiB
JavaScript

// Each tab keeps its own scroll position in the Writing, Reading, Split, and IDE layouts.
import assert from "node:assert/strict";
import { mockTauri, runSmoke, settle as settleFrames, smokeUrl } from "../_harness/index.mjs";
await runSmoke("tabs/scroll", async ({ page }) => {
await mockTauri(page, {
commands: test => test.workspace({
root: "C:\\smoke-workspace",
files: Object.fromEntries(["scroll-a.md", "scroll-b.md"].map(name => [name, Array.from({ length: 200 }, (_, i) => `Paragraph ${i} of ${name}.\n\n`).join("")])),
}),
});
const settle = () => settleFrames(page);
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 roundTrip(selector, label) {
const scroller = page.locator(selector);
const position = async (top) => scroller.evaluate((el, top) => {
if (top !== undefined) el.scrollTop = top;
return el.scrollTop;
}, top);
// The Writing layout restores a line-anchored CodeMirror scrollSnapshot (src/lib/editor/DocumentEditor.svelte:304-305).
// Re-estimated heights of the lines above can move scrollTop, so compare the top visible line and its offset.
const visibleTop = () => label === 'Writing'
? scroller.evaluate(async el => {
const { EditorView } = await import('/node_modules/@codemirror/view/dist/index.js');
const view = EditorView.findFromDOM(el.querySelector('.cm-content'));
const top = el.getBoundingClientRect().top - view.documentTop;
const block = view.lineBlockAtHeight(top);
return { line: view.state.doc.lineAt(block.from).number, offset: top - block.top };
})
: position().then(top => ({ line: 0, offset: top }));
await scroller.waitFor({ state: 'visible' });
await settle();
await position(1800);
await settle();
assert.ok(await position() > 1000, `${label}: first document is scrollable`);
const first = await visibleTop();
await page.getByRole('tab', { name: 'scroll-b.md', exact: true }).click();
await scroller.waitFor({ state: 'visible' });
await settle();
await position(650);
await settle();
const second = await visibleTop();
for (let repeat = 0; repeat < 2; repeat++) {
for (const [name, expected] of [['scroll-a.md', first], ['scroll-b.md', second]]) {
await page.getByRole('tab', { name, exact: true }).click();
await scroller.waitFor({ state: 'visible' });
await settle();
const actual = await visibleTop();
assert.ok(actual.line === expected.line && Math.abs(actual.offset - expected.offset) < 5, `${label}: ${name} expected ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}`);
}
}
console.log(`PASS: ${label} retains independent tab scroll positions`);
await page.getByRole('tab', { name: 'scroll-a.md', exact: true }).click();
}
// The view and layout switchers show only the current mode until hovered (src/lib/ui/ModeSwitcher.svelte:92, :153).
async function mode(group, name) {
const switcher = page.getByRole('group', { name: group, exact: true });
await switcher.hover();
await switcher.getByRole('button', { name, exact: true }).click();
}
await page.goto(smokeUrl);
await page.getByText('smoke-workspace', { exact: true }).waitFor();
await open('scroll-b.md');
await open('scroll-a.md');
await mode('Editor layout', 'Writer');
await roundTrip('.cm-scroller', 'Writing');
await mode('Document view', 'Read');
await roundTrip('.md-page', 'Reading');
await mode('Document view', 'Split');
await roundTrip('.md-page', 'Split preview');
await mode('Document view', 'Edit');
await mode('Editor layout', 'IDE');
await page.getByRole('tab', { name: 'scroll-b.md', exact: true }).click();
await mode('Editor layout', 'IDE');
await page.getByRole('tab', { name: 'scroll-a.md', exact: true }).click();
await roundTrip('.source-editor .cm-scroller', 'IDE');
});