From 6abc7f770495cd5ab02adfa8a7b0dfd7bda723b1 Mon Sep 17 00:00:00 2001 From: Steffen Becker Date: Fri, 4 Sep 2026 17:19:33 +0200 Subject: [PATCH] refactor: the kept versions are offered at a failed load, not in the menu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A list of timestamps in both file menus paid for itself only on the day something went wrong, and it was in the way on every other. The entries are gone; loadDocument now offers the versions where the browser copy has actually failed the reader — newest first, one question each, and the one taken up starts under the boot flag like any other document. The store loses its reactive singleton with them. --- README.md | 2 +- src/App.svelte | 34 ---------------- src/lib/components/ribbon/Ribbon.svelte | 13 +------ src/lib/i18n/locales/de.ts | 6 +-- src/lib/i18n/locales/en.ts | 6 +-- src/lib/storage/CLAUDE.md | 4 +- src/lib/storage/autosave.ts | 35 +++++++++++++---- .../{snapshots.svelte.ts => snapshots.ts} | 12 ++---- tests/fakeIdb.ts | 27 +++++++++++++ tests/unit/autosave-recovery.test.ts | 39 +++++++++++++++++++ tests/unit/snapshots.test.ts | 35 ++--------------- 11 files changed, 109 insertions(+), 104 deletions(-) rename src/lib/storage/{snapshots.svelte.ts => snapshots.ts} (87%) create mode 100644 tests/fakeIdb.ts diff --git a/README.md b/README.md index 922aff5..ca4df3a 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ EdenText is a web-based, powerful word processor for everything from quick notes > the way. It is tested — the full suite plus LibreOffice round-trip checks run > on every commit — but expect occasional bugs, and keep backups of documents > you care about. The browser copy also keeps the last three versions of the open -> document — File ▸ Earlier versions puts one back. +> document, and offers them if it ever fails to load one. [![EdenText editing a multi-column document](docs/screenshot.png)](https://edentext.app) Sample File from https://sample-files.com/ diff --git a/src/App.svelte b/src/App.svelte index 7880bca..540195d 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -46,7 +46,6 @@ import { loadLineNumbering, saveLineNumbering, DEFAULT_LINE_NUMBERING, type LineNumbering } from './lib/storage/lineNumbering'; import { loadFoldMarks, saveFoldMarks } from './lib/storage/foldMarks'; import { printMarkup } from './lib/storage/printMarkup.svelte'; - import { snapshots, loadSnapshots, readSnapshot } from './lib/storage/snapshots.svelte'; import { commentsInPane, changesInPane, markupAttrs, setShowChanges, setShowComments } from './lib/storage/markup.svelte'; import { loadDocumentLanguage, saveDocumentLanguage, odfFromLanguage, type DocumentLanguage } from './lib/storage/documentLanguage'; import { setTableLanguage } from './lib/storage/tableOptions.svelte'; @@ -1071,29 +1070,6 @@ } } - // The versions the autosave keeps aside, and the reader's label for one. - void loadSnapshots(); - function snapshotLabel(at: number): string { - return new Date(at).toLocaleString(locale(), { dateStyle: 'short', timeStyle: 'short' }); - } - - // Put an earlier version's text back. The page setup, the styles and the zones - // belong to the open document, so only the text is replaced. - async function handleRestoreSnapshot(at: number) { - exportMenuOpen = false; - if (!editor || !confirm(t().dialogs.confirmRestore(snapshotLabel(at)))) return; - const json = await readSnapshot(at); - if (!json) { - alert(t().dialogs.snapshotGone); - void loadSnapshots(); - return; - } - loadContent(json as Content); - documentEpoch++; - resetHistory(); - editor.commands.focus(); - } - function handleForgetRecent() { forgetRecentFiles(); recentFiles = []; @@ -1371,8 +1347,6 @@ recentFiles={recentFiles} onOpenRecent={(id) => { const f = recentFiles.find((r) => r.id === id); if (f) void handleOpenRecent(f); }} onForgetRecent={handleForgetRecent} - snapshots={snapshots().map((at) => ({ at, label: snapshotLabel(at) }))} - onRestoreSnapshot={(at) => void handleRestoreSnapshot(at)} onExportPdf={handleExportPdf} onPrintPdf={handlePrintPdf} onPrint={handlePrint} @@ -1510,14 +1484,6 @@ {t().app.clearRecentFiles} {/if} - {#if snapshots().length} -
{t().app.versions}
- {#each snapshots() as at (at)} - - {/each} - {/if} {/if} - {#if snapshots.length} -
- {#each snapshots as s (s.at)} - - {/each} - {/if}