Cancel button to revert unsaved changes in a section #11

Closed
opened 2026-11-09 21:03:49 +00:00 by eric · 0 comments
Owner

Add a Cancel button next to Save (top bar, edit mode only). It reverts all unsaved changes on the current section (or the Print header panel) back to the last Save/Open, and then leaves edit mode.

Behavior

  • Baseline = state at last Save or Open (in memory only, never persisted).
  • Per section: only the section being viewed reverts; other sections keep unsaved edits. Covers records, fields, images, items, intro.
  • Confirm prompt only if the section actually differs from the baseline; otherwise no prompt.
  • After Cancel the app exits edit mode (state.editing = false) and shows the reverted section in view mode. This happens whether or not anything changed.
  • Print header panel: restores doc.header, including the 'absent = default' case, then exits edit mode.
  • A section added this session has no baseline, so Cancel removes it and selects a neighbor, then exits edit mode.
  • Decided: deleting or reordering sections is document-wide and is NOT undone by Cancel. Cancel only undoes edits inside the section being viewed. No document-level 'Discard all changes' button. This is documented in MAINTENANCE.md/README. Stronger protection against accidental section deletes is tracked separately.

Implementation

  1. state.baseline = structuredClone(state.doc) after unlock, new-document creation, and each successful save (snapshot() helper).
  2. Pure helpers in src/ops.js: sectionDiffers, revertSection (and header equivalents).
  3. revertCurrent() in src/app.js: revert, set state.editing = false, re-render; recompute state.dirty as 'document differs from baseline' (ignoring meta.lastUpdated) so the Unsaved badge and beforeunload warning stay correct.
  4. Docs: paragraph in docs/MAINTENANCE.md and README.

Tests

  • Unit (node --test): revert edited section, section added this session, header back to default, other sections untouched.
  • Headless Chromium: edit/add/remove field and replace image then Cancel (assert view mode and original content); Save, edit, Cancel returns to saved state; Cancel with no changes still exits edit mode; badge clears when last change is undone; Cancel on Print header.
Add a **Cancel** button next to **Save** (top bar, edit mode only). It reverts all unsaved changes on the current section (or the Print header panel) back to the last Save/Open, **and then leaves edit mode**. ## Behavior - Baseline = state at last Save or Open (in memory only, never persisted). - Per section: only the section being viewed reverts; other sections keep unsaved edits. Covers records, fields, images, items, intro. - Confirm prompt only if the section actually differs from the baseline; otherwise no prompt. - **After Cancel the app exits edit mode** (state.editing = false) and shows the reverted section in view mode. This happens whether or not anything changed. - Print header panel: restores doc.header, including the 'absent = default' case, then exits edit mode. - A section added this session has no baseline, so Cancel removes it and selects a neighbor, then exits edit mode. - **Decided:** deleting or reordering sections is document-wide and is NOT undone by Cancel. Cancel only undoes edits inside the section being viewed. No document-level 'Discard all changes' button. This is documented in MAINTENANCE.md/README. Stronger protection against accidental section deletes is tracked separately. ## Implementation 1. state.baseline = structuredClone(state.doc) after unlock, new-document creation, and each successful save (snapshot() helper). 2. Pure helpers in src/ops.js: sectionDiffers, revertSection (and header equivalents). 3. revertCurrent() in src/app.js: revert, set state.editing = false, re-render; recompute state.dirty as 'document differs from baseline' (ignoring meta.lastUpdated) so the Unsaved badge and beforeunload warning stay correct. 4. Docs: paragraph in docs/MAINTENANCE.md and README. ## Tests - Unit (node --test): revert edited section, section added this session, header back to default, other sections untouched. - Headless Chromium: edit/add/remove field and replace image then Cancel (assert view mode and original content); Save, edit, Cancel returns to saved state; Cancel with no changes still exits edit mode; badge clears when last change is undone; Cancel on Print header.
eric closed this issue 2026-11-09 23:24:28 +00:00
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: eric/final-wishes#11
No description provided.