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
+17 -7
View File
@@ -7,6 +7,7 @@
import type { Documents } from "$lib/workspace/documents.svelte";
import type { OpenBuffer } from "$lib/workspace/types";
import EditorPane from "./EditorPane.svelte";
import Icon from "$lib/ui/Icon.svelte";
import type { ViewMode } from "./ViewModes.svelte";
import TabBar from "./TabBar.svelte";
@@ -42,11 +43,12 @@
linkActions: (pane: DocumentView) => EditorProps["linkActions"];
onView: (pane: DocumentView, view: ViewMode) => void;
onSplitView: (pane: DocumentView, split: boolean) => void;
onCursor: (pane: DocumentView, line: number, column: number) => void;
onOpenLink: (pane: DocumentView, kind: "md" | "wiki", target: string) => void;
};
let { editorPluginVisible, split, pluginBounds, tabBar, pluginPaneComponents = $bindable(), documentViews, activePane, paneComponents = $bindable(),
documents, tabs, hasWorkspace, browserOpening, focusLine, onFocusPane, onCloseSplit, onSaveCopy, onOpenWorkspace, onNewFile, onNewNote,
onQuickOpen, onOpenBrowser, onChange, onInsertImage, onRenameTitle, tableActions, linkActions, onView, onSplitView, onOpenLink }: Props = $props();
onQuickOpen, onOpenBrowser, onChange, onInsertImage, onRenameTitle, tableActions, linkActions, onView, onSplitView, onCursor, onOpenLink }: Props = $props();
</script>
<main class="center">
@@ -76,13 +78,15 @@
onpointerdowncapture={() => onFocusPane(pane.id)}
onfocusin={() => onFocusPane(pane.id)}>
{#if pane.buffer?.diskError}
<div class="conflict" role="alert"><span>{pane.buffer.diskError}</span><button onclick={() => onSaveCopy(pane.buffer)}>{$t("Save a copy")}</button><button onclick={() => void documents?.refresh()}>{$t("Retry")}</button></div>
<div class="conflict" role="alert"><Icon icon="alert" /><span>{pane.buffer.diskError}</span><button class="primary" onclick={() => void documents?.refresh()}>{$t("Retry")}</button><button onclick={() => onSaveCopy(pane.buffer)}>{$t("Save a copy")}</button></div>
{:else if pane.buffer?.diskContents != null}
<div class="conflict" role="alert">
<!-- The safe choice comes first. The choice that discards your edits comes last, in the error color. -->
<Icon icon="alert" />
<span>{$t("This file changed on disk. Your edits are preserved. Review both versions before saving.")}</span>
<button onclick={() => { if (pane.buffer) documents?.resolve(pane.buffer.id, true); }}>{$t("Use disk version")}</button>
<button onclick={() => { if (pane.buffer) documents?.resolve(pane.buffer.id, false); }}>{$t("Keep my edits")}</button>
<button class="primary" onclick={() => { if (pane.buffer) documents?.resolve(pane.buffer.id, false); }}>{$t("Keep my edits")}</button>
<button onclick={() => onSaveCopy(pane.buffer)}>{$t("Save a copy")}</button>
<button class="danger" onclick={() => { if (pane.buffer) documents?.resolve(pane.buffer.id, true); }}>{$t("Use disk version")}</button>
</div>
<details class="disk-review"><summary>{$t("View disk version")}</summary><pre>{pane.buffer.diskContents}</pre></details>
{/if}
@@ -110,6 +114,7 @@
linkActions={linkActions(pane)}
onView={view => onView(pane, view)}
onSplit={next => onSplitView(pane, next)}
onCursor={(line, column) => onCursor(pane, line, column)}
onOpenLink={(kind, target) => onOpenLink(pane, kind, target)}
/>
</div>
@@ -130,9 +135,14 @@
background: transparent;
}
.conflict { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px; background: var(--rs-bg-active); border-bottom: 1px solid var(--rs-warn); }
.conflict span { flex: 1 1 300px; }
.conflict button { border: 1px solid var(--rs-border); background: var(--rs-bg); padding: 4px 8px; }
/* The conflict banner uses the warning status color and icon. Its text and buttons wrap in a narrow pane. */
.conflict { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px; background: color-mix(in srgb, var(--rs-warn) 14%, var(--rs-bg)); border-bottom: 2px solid var(--rs-warn); color: var(--rs-text-strong); }
.conflict > :global(svg) { width: 18px; height: 18px; flex-shrink: 0; color: var(--rs-warn); }
.conflict span { flex: 1 1 220px; min-width: 0; }
.conflict button { min-height: 28px; border: 1px solid var(--rs-border); border-radius: var(--rs-control-radius); background: var(--rs-bg); color: var(--rs-text); padding: 4px 10px; }
.conflict button:hover { background: var(--rs-bg-active); }
.conflict button.primary { border-color: var(--rs-accent); background: var(--rs-accent); color: var(--rs-on-accent); }
.conflict button.danger { border-color: var(--rs-error); color: var(--rs-error); }
.disk-review { padding: 8px 12px; max-height: 35vh; overflow: auto; flex: 0 0 auto; }
.disk-review pre { white-space: pre-wrap; user-select: text; }
+3 -2
View File
@@ -31,6 +31,7 @@
onInsertImage?: (file: File) => Promise<string | null>;
onView?: (view: ViewMode) => void;
onSplit?: (split: boolean) => void;
onCursor?: (line: number, column: number) => void;
onOpenLink?: (kind: "md" | "wiki", target: string) => void;
onOpenWorkspace: () => void;
onNewFile: () => void;
@@ -45,7 +46,7 @@
onCloseSplit?: () => void;
};
let { buffer, tabs, chrome, reading, split, focusLine, onChange, onRenameTitle, onInsertImage, onView, onSplit, onOpenLink, onOpenWorkspace, onNewFile, onNewNote, onQuickOpen, onOpenBrowser, browserOpening = false, hasWorkspace, tableActions, linkActions, active = true, onCloseSplit }: Props = $props();
let { buffer, tabs, chrome, reading, split, focusLine, onChange, onRenameTitle, onInsertImage, onView, onSplit, onCursor, onOpenLink, onOpenWorkspace, onNewFile, onNewNote, onQuickOpen, onOpenBrowser, browserOpening = false, hasWorkspace, tableActions, linkActions, active = true, onCloseSplit }: Props = $props();
let selectedLine = $state(1);
let lineInfo = $state<GitLineInfo | null>(null);
const git = $derived.by(() => { void $pluginHost; return pluginHost.get("git"); });
@@ -187,7 +188,7 @@
<div class="editor-wrap" class:hidden={readOnly}>
{#key buffer.id}
<DocumentEditor bind:this={documentEditor} {buffer} mode={chrome === "Writing" && canPreview && !readOnly ? "write" : "source"} {chrome}
{onChange} {onRenameTitle} {onInsertImage} {onOpenLink} {linkActions} {focusLine} {tableActions} {shouldFocusOnMount} onSelectionLine={(line) => selectedLine = line}
{onChange} {onRenameTitle} {onInsertImage} {onOpenLink} {linkActions} {focusLine} {tableActions} {shouldFocusOnMount} onSelectionLine={(line, column) => { selectedLine = line; onCursor?.(line, column); }}
focusTitle={titleFocusId === buffer.id} onTitleFocused={() => { titleFocusId = null; }} />
{/key}
</div>
+4
View File
@@ -147,6 +147,10 @@
<div><label for="show-file-title">{$t("File name title")}</label><p id="file-title-description">{$t("Show the file name above each Markdown note in Write and Read.")}</p></div>
<input id="show-file-title" class="rs-switch" type="checkbox" role="switch" aria-describedby="file-title-description" checked={settings.showFileTitle} onchange={event => apply({ ...settings, showFileTitle: event.currentTarget.checked })} />
</div>
<div class="setting-row">
<div><label for="keep-line-breaks">{$t("Keep line breaks")}</label><p id="line-breaks-description">{$t("Show each line break of the source in Read. When this is off, Read joins the lines of a paragraph, as CommonMark does.")}</p></div>
<input id="keep-line-breaks" class="rs-switch" type="checkbox" role="switch" aria-describedby="line-breaks-description" checked={settings.keepLineBreaks} onchange={event => apply({ ...settings, keepLineBreaks: event.currentTarget.checked })} />
</div>
</div>
<h3>{$t("Tables")}</h3>
<div class="card">
+19 -11
View File
@@ -1,16 +1,22 @@
<script lang="ts">
// The status bar at the bottom of the workbench.
// The status bar at the bottom of the workbench: the last message, then the facts of the active document.
import { t } from "$lib/i18n";
import type { ViewMode } from "./ViewModes.svelte";
// `view` is the view of the active text document, or null for other tabs.
let { message, watchMode, view }: { message: string; watchMode: string | null; view: ViewMode | null } = $props();
type Facts = { saved: boolean; line: number; column: number; words: number; endings: "LF" | "CRLF" };
// `view` and `facts` belong to the active text document. They are null for other tabs.
// `polling` is true when the workspace is on a network drive, where RuneStone polls for changes.
let { message, polling, view, facts }: { message: string; polling: boolean; view: ViewMode | null; facts: Facts | null } = $props();
</script>
<footer class="status">
<span>{message}</span>
{#if watchMode}
<span>{watchMode} watch</span>
<span class="message">{message}</span>
{#if polling}<span title={$t("This folder is on a network drive. RuneStone checks it for changes at intervals.")}>{$t("Polling for changes")}</span>{/if}
{#if facts}
<span class:unsaved={!facts.saved}>{facts.saved ? $t("Saved") : $t("Unsaved")}</span>
<span>{$t("Ln {line}, Col {column}", { line: facts.line, column: facts.column })}</span>
<span>{facts.words === 1 ? $t("1 word") : $t("{count} words", { count: facts.words })}</span>
<span>{facts.endings}</span>
{/if}
{#if view}<span>{view === "read" ? $t("Read") : view === "source" ? $t("Source") : $t("Write")}</span>{/if}
</footer>
@@ -19,22 +25,24 @@
.status {
grid-column: 1 / -1;
display: flex;
justify-content: space-between;
gap: 12px;
gap: 16px;
padding: 0 10px;
background: var(--rs-bg-elevated);
border-top: 1px solid var(--rs-border);
color: var(--rs-text-dim);
font-size: 12px;
white-space: nowrap;
overflow: hidden;
}
/* The message takes the free space, so the other items stay at the right. */
.status :first-child {
/* The message takes the free space, so the facts stay at the right. */
.message {
flex: 1;
min-width: 0;
color: var(--rs-text);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.unsaved { color: var(--rs-text-strong); }
</style>
+33 -5
View File
@@ -16,7 +16,7 @@
import type { Contributions } from "$lib/plugins/contracts";
import { invoke, isTauri } from "@tauri-apps/api/core";
import { getCurrentWindow } from "@tauri-apps/api/window";
import { confirm } from "@tauri-apps/plugin-dialog";
import { confirm, message as dialogMessage } from "@tauri-apps/plugin-dialog";
import { openUrl } from "@tauri-apps/plugin-opener";
import { Documents } from "$lib/workspace/documents.svelte";
import { documentSessionKey, parseDocumentSession, restoreDocumentSession, type DocumentSession } from "$lib/workspace/documentSession";
@@ -369,9 +369,27 @@
const readable = $derived(buffer?.kind === "text" && isMarkdownPath(buffer.relPath));
// The status bar names the view of the active pane. Split shows the editor view.
const viewMode: ViewMode = $derived(reading && readable ? "read" : isSource ? "source" : "write");
// The outline and the status bar follow the active tab. A plugin or browser tab has no document facts.
const documentActive = $derived(!editorPluginVisible && buffer?.kind === "text");
const outlineItems = $derived(
buffer && buffer.kind === "text" ? buildOutline(buffer.relPath, buffer.contents) : [],
documentActive && buffer ? buildOutline(buffer.relPath, buffer.contents) : [],
);
let cursor = $state({ line: 1, column: 1 });
$effect(() => { void buffer?.id; cursor = { line: 1, column: 1 }; });
const documentFacts = $derived(documentActive && buffer ? {
saved: buffer.contents === buffer.saved,
line: cursor.line,
column: cursor.column,
words: countWords(buffer.contents),
endings: buffer.saved.includes("\r\n") ? "CRLF" as const : "LF" as const,
} : null);
/** Words separated by space, and each Han, Hiragana, or Katakana character as one word. */
function countWords(text: string) {
const ideographs = text.match(/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}]/gu)?.length ?? 0;
const rest = text.replace(/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}]/gu, " ").trim();
return ideographs + (rest ? rest.split(/\s+/).length : 0);
}
function applyChrome(next: Chrome) {
view = next;
@@ -650,8 +668,17 @@
if ("buffer" in target) {
if (!tab) continue;
const contents = tab.contents;
if (contents !== tab.saved && !await confirm($t("Discard unsaved edits in {name}?", { name: tab.name }), { title: $t("Close document"), kind: "warning" })) break;
if (documents !== current || switching || tab.contents !== contents) break;
if (contents !== tab.saved) {
// The platform choices for a changed document: Save, Don't save, or Cancel.
const labels = { yes: $t("Save"), no: $t("Don't save"), cancel: $t("Cancel") };
const choice = await dialogMessage($t("Save the changes to {name}?", { name: tab.name }), { title: $t("Close document"), kind: "warning", buttons: labels });
if (choice !== labels.yes && choice !== "Yes" && choice !== labels.no && choice !== "No") break;
if (documents !== current || switching || tab.contents !== contents) break;
if (choice === labels.yes || choice === "Yes") {
try { await current!.save(tab.id); } catch (reason) { error = String(reason); break; }
}
}
if (documents !== current || switching) break;
if (scope !== "one" && tab.pinned) continue;
}
const index = workingTabs.findIndex(item => item.id === target.id);
@@ -1353,6 +1380,7 @@
})}
onView={(pane, next) => setDocumentView(pane.id, next)}
onSplitView={(pane, next) => setSplitView(pane.id, next)}
onCursor={(pane, line, column) => { if (pane.id === documentPanes.active) cursor = { line, column }; }}
onOpenLink={(pane, kind, target) => void openLink(kind, target, pane.buffer?.relPath ?? "", pane.id)}
/>
{#if terminalContribution && terminalStarted}
@@ -1414,7 +1442,7 @@
/>
{/if}
<StatusBar message={error ?? status} watchMode={workspace?.watch_mode ?? null} view={buffer?.kind === "text" ? viewMode : null} />
<StatusBar message={error ?? status} polling={workspace?.watch_mode === "poll"} view={documentActive ? viewMode : null} facts={documentFacts} />
</div>
<style>
+4
View File
@@ -36,6 +36,10 @@
.document-title, .reading .document-title { margin: 0 0 .85em; color: var(--rs-text-strong); font: var(--rs-heading-weight) 1.8em/1.3 var(--rs-font-heading); overflow-wrap: anywhere; }
.reading > :first-child { margin-top: 0; }
.reading p { margin: 0 0 .75em; white-space: pre-line; }
/* Read follows CommonMark soft breaks by default. The Keep line breaks setting shows each source line break.
The table preview and cell editors of Write keep their line breaks: their editing depends on them. */
.reading:not(.writer-preview) p { white-space: normal; }
:root[data-keep-line-breaks] .reading:not(.writer-preview) p { white-space: pre-line; }
.reading strong { font-weight: 600; color: var(--rs-text-strong); }
.reading a { color: var(--rs-link); text-decoration-thickness: 1px; text-underline-offset: 3px; }
.reading a:hover { color: var(--rs-accent-2); }