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:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user