Ask Save or Don't save, and show useful status facts

Phase 5-7.

- A changed tab asks Save, Don't save, or Cancel through the native
  dialog, instead of OK and Cancel to discard.
- The conflict banner uses --rs-warn with a warning icon. Keep my
  edits is the primary choice and comes first. Use disk version comes
  last, in the error color. The banner wraps in a narrow pane.
- The status bar shows the save state, the line and column, the word
  count, the line endings, and the view. It shows the watch mode only
  when it polls a network folder.
- The outline and the document facts follow the active tab. A tab
  without a document has no outline and no document facts.
- Tables: only formula cells have a hover hint, so no hint covers the
  next cell. The table adds no gap above its control area. The add
  controls show while a cell has focus.
- The plugin review marks Install and enable as the primary action. The
  other choice is Install, keep disabled.
- Read follows CommonMark soft breaks. Settings, General, Keep line
  breaks shows each source line break. The table preview and cell
  editors of Write keep their line breaks, because their editing
  depends on them.
- Catalog rows in French, Japanese, and Simplified Chinese.
- Docs: UI-053, the user guide, and plugins.md.

Tests: the new layout/plainFixes, the keepLineBreaks cases in the
settings unit tests, and the new install button name.
This commit is contained in:
Knotty Wyvern
2026-10-28 22:06:13 -07:00
parent 0fdc991b2e
commit eeddd880e1
24 changed files with 294 additions and 70 deletions
+125
View File
@@ -0,0 +1,125 @@
// Plain fixes: Save, Don't save, and Cancel when a changed tab closes, the conflict banner, the status bar facts,
// panes that follow the active tab, table hints and controls, and the line break setting.
import assert from "node:assert/strict";
import { chooseView, mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
await runSmoke("layout/plainFixes", async ({ page }) => {
const output = await outputDir("layout/plainFixes");
await mockTauri(page, {
state: { answer: "Cancel" },
commands: test => {
const workspace = test.workspace({
root: "C:\\plain",
files: {
"a.md": "# Alpha\n\nFirst line\nsecond line of the same paragraph.\n",
"b.md": "# Beta\r\n\r\nWindows text.\r\n",
"c.md": "# Gamma\n\nThird note.\n",
"table.md": "| Name | Value |\n| --- | --- |\n| One | 1 |\n| Two | =B2*2 |\n",
},
});
Object.assign(test, { files: workspace.files });
return {
...workspace,
plugins_snapshot: () => ({ root: "C:/plugins", plugins: [] }),
"plugin:window|is_maximized": () => false,
"plugin:dialog|message": args => { (test.state.prompts ??= []).push(args); return test.state.answer; },
};
},
});
await page.setViewportSize({ width: 1280, height: 800 });
await page.goto(smokeUrl);
await page.getByText("plain", { exact: true }).waitFor();
await page.evaluate(() => window.__TEST__.writeSettings("general", { autosaveEnabled: false, autosaveSeconds: 5 }));
const open = async 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", { name, exact: true, selected: true }).waitFor();
};
const status = () => page.locator(".status").innerText();
const type = async text => { await page.locator(".cm-content").click(); await page.keyboard.press("Control+End"); await page.keyboard.type(text); };
const answer = value => page.evaluate(value => { window.__TEST__.state.answer = value; }, value);
const file = name => page.evaluate(name => window.__TEST__.files.get(name), name);
// The status bar shows the save state, the cursor, the words, the line endings, and the view. Native watching has no label.
await open("a.md");
await page.locator(".cm-content").click();
await page.keyboard.press("Control+Home");
await page.waitForFunction(() => /Ln 1, Col 1/.test(document.querySelector(".status").textContent));
assert.match(await status(), /Saved/);
assert.match(await status(), /10 words/);
assert.match(await status(), /LF/);
assert.doesNotMatch(await status(), /watch/i);
await open("b.md");
await page.waitForFunction(() => /CRLF/.test(document.querySelector(".status").textContent));
await page.locator(".status").screenshot({ path: `${output}/status.png` });
// Closing a changed tab asks Save, Don't save, or Cancel.
await type(" Edited");
await page.waitForFunction(() => /Unsaved/.test(document.querySelector(".status").textContent));
const prompts = () => page.evaluate(() => window.__TEST__.state.prompts ?? []);
await page.keyboard.press("Control+w");
await page.waitForFunction(() => (window.__TEST__.state.prompts ?? []).length === 1);
assert.deepEqual((await prompts())[0].buttons, { YesNoCancelCustom: ["Save", "Don't save", "Cancel"] });
assert.equal(await page.getByRole("tab", { name: /^b\.md/ }).count(), 1, "Cancel keeps the tab");
await answer("Save");
await page.keyboard.press("Control+w");
await page.getByRole("tab", { name: /^b\.md/ }).waitFor({ state: "detached" });
assert.match(await file("b.md"), /Edited/);
await open("c.md");
await type(" Dropped");
await answer("Don't save");
await page.keyboard.press("Control+w");
await page.getByRole("tab", { name: /^c\.md/ }).waitFor({ state: "detached" });
assert.doesNotMatch(await file("c.md"), /Dropped/);
// The conflict banner: the warning icon, the safe choice first, and the choice that discards edits last.
await open("a.md");
await type(" Mine");
await page.evaluate(() => {
window.__TEST__.files.set("a.md", "# Alpha\n\nChanged on disk.\n");
window.__TEST__.emit("workspace-event", { root: "C:\\plain", kind: "modify", paths: ["a.md"] });
});
const banner = page.locator(".conflict");
await banner.waitFor();
assert.equal(await banner.locator("svg").count(), 1);
assert.deepEqual(await banner.getByRole("button").allInnerTexts(), ["Keep my edits", "Save a copy", "Use disk version"]);
const color = token => page.evaluate(token => { const probe = document.createElement("span"); probe.style.color = `var(${token})`; document.body.append(probe); const value = getComputedStyle(probe).color; probe.remove(); return value; }, token);
assert.equal(await banner.getByRole("button", { name: "Use disk version" }).evaluate(node => getComputedStyle(node).color), await color("--rs-error"));
assert.equal(await banner.evaluate(node => getComputedStyle(node).borderBottomColor), await color("--rs-warn"));
await page.setViewportSize({ width: 880, height: 800 });
assert.ok(await banner.evaluate(node => node.scrollWidth <= node.clientWidth + 1), "The banner wraps in a narrow pane");
await page.screenshot({ path: `${output}/conflict-narrow.png` });
await page.setViewportSize({ width: 1280, height: 800 });
await banner.getByRole("button", { name: "Keep my edits" }).click();
await banner.waitFor({ state: "detached" });
// Read follows CommonMark soft breaks by default. The setting keeps each source line break.
await page.keyboard.press("Control+s");
await chooseView(page, "Read");
const paragraph = page.locator(".md-page .reading p").first();
assert.equal(await paragraph.evaluate(node => getComputedStyle(node).whiteSpace), "normal");
await page.evaluate(() => window.__TEST__.writeSettings("general", { ...window.__TEST__.settings("general"), keepLineBreaks: true }));
await page.waitForFunction(() => getComputedStyle(document.querySelector(".md-page .reading p")).whiteSpace === "pre-line");
await page.evaluate(() => window.__TEST__.writeSettings("general", { ...window.__TEST__.settings("general"), keepLineBreaks: false }));
await chooseView(page, "Write");
// A plain table cell has no hover hint, because the footer shows its address. The controls show while a cell has focus.
await open("table.md");
const table = page.locator(".live-writer .writer-table");
await table.waitFor();
await table.locator("td").first().hover();
await page.waitForTimeout(500);
assert.equal(await page.locator(".rs-tooltip:popover-open").count(), 0);
await table.locator("td").first().click();
await page.waitForFunction(() => getComputedStyle(document.querySelector(".writer-table .table-add")).opacity === "1");
await page.keyboard.press("Escape");
// The outline and the status bar follow the active tab: a tab without a document has no outline and no document facts.
await page.evaluate(() => window.__TEST__.emit("runestone-theme-editor-open", null));
await page.getByRole("tab", { name: "Theme editor", exact: true, selected: true }).waitFor();
await page.waitForFunction(() => !/Ln \d/.test(document.querySelector(".status").textContent));
assert.equal(await page.locator("aside.right li").count(), 0);
assert.deepEqual(page.errors, []);
console.log("PASS: status bar facts, Save, Don't save, and Cancel on close, conflict banner order and colors, line break setting, table hints and controls, panes that follow the active tab.");
});
+4 -1
View File
@@ -358,7 +358,8 @@ await runSmoke("layout/workbench", async ({ page }) => {
assert.equal(await tableHeading.innerText(), '# Table layout');
await table.locator('tbody tr').first().locator('td').first().click();
await page.waitForFunction(() => document.querySelector('.live-writer .writer-heading')?.textContent === 'Table layout');
await page.waitForFunction(() => [...document.querySelectorAll('.table-add')].every(button => getComputedStyle(button).opacity === '0'));
// The add controls show while a cell of the table has focus (src/lib/editor/DocumentEditor.svelte).
await page.waitForFunction(() => [...document.querySelectorAll('.table-add')].every(button => getComputedStyle(button).opacity === '1'));
await page.keyboard.press('Control+s');
assert.equal(await page.evaluate(() => window.__TEST__.files.get('tables.md')), tableSource);
assert.equal(await table.locator('th').count(), 5);
@@ -374,6 +375,8 @@ await runSmoke("layout/workbench", async ({ page }) => {
assert.ok(await page.locator('.cm-scroller').evaluate(el => el.scrollWidth <= el.clientWidth + 1));
const addColumn = page.getByRole('button', { name: 'Add column to the right', exact: true });
const addRow = page.getByRole('button', { name: 'Add row below', exact: true });
// The add controls show on hover, and also while a cell of the table has focus. This part checks hover alone.
await page.evaluate(() => document.activeElement?.blur());
await addColumn.hover();
await page.waitForFunction(() => getComputedStyle(document.querySelector('.table-add-column')).opacity === '1');
assert.equal(await addRow.evaluate(el => getComputedStyle(el).opacity), '0');
+3 -3
View File
@@ -88,9 +88,9 @@ await runSmoke("links/linkEditing", async ({ page }) => {
for (const mode of ['light','dark']) {
await page.evaluate(async mode => (await import('/src/lib/theme/appearance.ts')).saveAppearance({theme:'default',mode}),mode);
await page.locator('.writer-table td').nth(1).hover();
await page.locator('.rs-tooltip:popover-open').waitFor();
// Table formulas are on by default, so the cell tooltip shows the cell address.
assert.equal(await page.locator('.rs-tooltip:popover-open').innerText(),'B2');
// Only a formula cell has a hover hint. The footer shows the address of the cell with focus (src/lib/editor/tableControls.ts).
await page.waitForTimeout(500);
assert.ok((await page.locator('.rs-tooltip:popover-open').allInnerTexts()).every(text => !/^[A-Z]+\d+/.test(text)));
await page.screenshot({path:path.join(output, 'editor-cell-tooltip-narrow-'+mode+'.png')});
await page.keyboard.press('Escape');
await page.mouse.move(5,90);
+2 -1
View File
@@ -84,7 +84,8 @@ await runSmoke("links/workspaceLinks", async ({ page }) => {
});
await backlink('moved/wiki.md').waitFor();
assert.equal(await backlink('wiki.md').count(),0);
await page.evaluate(()=>{window.__TEST__.answer='Ok';});
// A changed tab asks Save, Don't save, or Cancel (src/lib/layout/Workbench.svelte).
await page.evaluate(()=>{window.__TEST__.answer="Don't save";});
await page.getByRole('tab',{name:/^source\.md(?: •)?$/}).click();
await page.keyboard.press('Control+w');
await page.getByRole('tab',{name:/^source\.md(?: •)?$/}).waitFor({state:'detached'});
+1 -1
View File
@@ -175,7 +175,7 @@ await runSmoke("plugins/install", async ({ browser }) => {
await shot("plugin-git-narrow.png");
assert.equal(await gitDialog.evaluate(element => element.scrollWidth > element.clientWidth), false);
await gitDialog.getByRole("button", { name: "Review release", exact: true }).click();
await review.getByRole("button", { name: "Install", exact: true }).click();
await review.getByRole("button", { name: "Install, keep disabled", exact: true }).click();
await settingsDialog.getByRole("switch", { name: "Workspace overview", exact: true }).waitFor();
assert.equal(await settingsDialog.getByRole("switch", { name: "Workspace overview", exact: true }).isChecked(), false);
assert.equal(await count("plugins_from_git"), 3);
+2 -1
View File
@@ -105,7 +105,8 @@ await runSmoke("tabs/menus", async ({ page }) => {
await item("Close all").click();
await page.waitForFunction(() => window.__TEST__.prompts.length === 1);
assert.deepEqual(await order(), ["b.md", "c.md"]);
await page.evaluate(() => { window.__TEST__.answer = "Ok"; });
// A changed tab asks Save, Don't save, or Cancel (src/lib/layout/Workbench.svelte).
await page.evaluate(() => { window.__TEST__.answer = "Don't save"; });
await show("c.md •");
await item("Close all").click();
await tab("c.md •").waitFor({ state: "detached" });