Phase 5-3. - One radio group shows Write, Source, and Read at all times, with an icon and a name. Narrow panes show only the icons. The arrow keys move the choice, and the group has one Tab stop. The current choice gets the selection fill and an accent bar. Hover gets only a fill. - A Split toggle shows Read beside Write or Source. Each document pane keeps a split flag beside its reading flag. Read ends Split. - Ctrl+Shift+E switches between Read and the editor. Ctrl+E still switches between Write and Source. - "IDE" becomes "Source" in the Chrome type, the tab menu (a View submenu), the status bar, the catalog, the tests, and the docs. - Settings, General, File name title hides the title in Write and Read. It is on by default. - The breadcrumb shows only the folder of the file. The status bar shows the view, not the path. - ModeSwitcher.svelte and its hover test are gone. The new test layout/viewModes covers the control. - The command palette from 5-2 gets its row in docs/menu-surfaces.json. - The user guide Format table is whole again. The 5-2 edit had put the Paragraph and Insert rows under the shortcut table. - 8 new catalog rows and 10 removed rows, in French, Japanese, and Simplified Chinese. - Docs: UI-049, the user guide, ui-design.md, document-tools.md, development.md, and the README feature list. Tests: the new layout/viewModes, new cases in documentPanes.spec.ts and settings.spec.ts, and the chooseView harness helper. 21 smoke tests use the new control. Tests that read the full path from the breadcrumb now read its tooltip.
77 lines
3.7 KiB
JavaScript
77 lines
3.7 KiB
JavaScript
// Each tab keeps its own scroll position in the Writing, Reading, Split, and Source layouts.
|
|
import assert from "node:assert/strict";
|
|
import { chooseView, 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();
|
|
}
|
|
|
|
await page.goto(smokeUrl);
|
|
await page.getByText('smoke-workspace', { exact: true }).waitFor();
|
|
await open('scroll-b.md');
|
|
await open('scroll-a.md');
|
|
await chooseView(page, 'Write');
|
|
await roundTrip('.cm-scroller', 'Writing');
|
|
await chooseView(page, 'Read');
|
|
await roundTrip('.md-page', 'Reading');
|
|
await chooseView(page, 'Split');
|
|
await roundTrip('.md-page', 'Split preview');
|
|
await chooseView(page, 'Split');
|
|
await chooseView(page, 'Source');
|
|
await page.getByRole('tab', { name: 'scroll-b.md', exact: true }).click();
|
|
await chooseView(page, 'Source');
|
|
await page.getByRole('tab', { name: 'scroll-a.md', exact: true }).click();
|
|
await roundTrip('.source-editor .cm-scroller', 'Source');
|
|
});
|