Skip to content

AutoSave: ask where to save before turning on, save in batches, and save on close - #4849

Draft
jcabezasb wants to merge 1 commit into
storytold:mainfrom
jcabezasb:autosave-ask-to-save-and-batch
Draft

jcabezasb wants to merge 1 commit into
storytold:mainfrom
jcabezasb:autosave-ask-to-save-and-batch

Conversation

@jcabezasb

Copy link
Copy Markdown

AutoSave now works for a new workbook: turning it on asks where to save first. Changes are saved in batches instead of rewriting the file every couple of seconds, and closing a workbook with AutoSave on saves it instead of asking.

Fixes #4847. Part of #4082: covers the CSV case reported there, not the macOS reopen problem.

Draft until 2026-11-28 15:40 UTC: I asked on #2017, #2973 and #972, which touch the same code, whether they are still active, and said I would wait 24 hours (standards/claims.md).

What the user saw

  • Turning on AutoSave for a workbook without an .xlsx file (new, or opened from CSV) showed the switch on, but nothing was ever saved, and nothing said so.
  • A save that AutoSave could not make was retried silently every 2 seconds.
  • With a file, the whole workbook was rewritten about 2 s after every change.
  • Closing a workbook with AutoSave on still asked "Save Changes?".

Cause

toggle_autosave only flipped UiState::autosave. SheetApp::autosave then skipped every workbook whose path was not .xlsx, and ignored the result of file.save. Closing never looked at AutoSave.

What changed

All in crates/ui-egui:

  • Turning it on (toggle_autosave, app/files.rs): for a workbook without an .xlsx file, Save As runs first. AutoSave turns on only if the workbook then has an .xlsx file, so a cancelled save leaves it off. Without a file picker (web), it stays off with a message. Turning it off is unchanged.
  • What the switch shows (SheetApp::autosave_active): the switch and the Options checkbox are on only when the preference is on and the active workbook has an .xlsx file. With the preference on, a workbook without a file shows the switch off, and clicking it asks where to save that workbook instead of turning AutoSave off.
  • Batches (SheetApp::autosave): unsaved changes are collected in a batch (GridState::autosave_batch), counted with DocState::revision. The batch is saved when 10 changes have piled up, or 30 s after its first change, whichever comes first. As before, it waits while a cell or text box is being edited. Switching workbooks starts a new batch. The repaint request waits for the batch's deadline instead of firing every 2 s.
  • A failed save turns AutoSave off and shows the error (AGENTS.md rule 15), instead of retrying without saying so. This overlaps Fix temporary-save collisions and silent AutoSave failures #972.
  • Closing: a workbook AutoSave can write to is saved instead of asked about, both when quitting (continue_quit, app/quit.rs) and when closing one workbook (its window's close button runs window.close, or File › Close: open_dialog intercepts the engine's Save Changes request and closes the workbook as answering Save would). A workbook without a file, or one whose save fails, is still asked about. This overlaps Save latest edits before quitting with AutoSave #2973.
  • Status (SheetApp::autosave_status): next to the switch, while the preference is on, "Saving…" while changes wait for their batch, "Saved" once the file has them, and "Not saved to a file" for a workbook AutoSave can't write to.

The engine's file.save and the persisted preference (#1995) are untouched. Version history and a registered command for the switch are left for their own issues.

Tests

New:

  • turning_autosave_on_asks_to_save_a_workbook_without_a_file: with no file picker, AutoSave stays off and a message shows; a cancelled save leaves it off; a picked file is saved as .xlsx and AutoSave turns on. With the preference on, a workbook without a file shows the switch off, and clicking it saves that workbook first.
  • autosave_waits_after_a_single_change: one fresh change is not saved yet and waits in a batch.
  • autosave_saves_a_burst_of_changes_at_once: enough changes in a row are saved before the delay, and the save leaves the workbook clean.
  • autosave_status_follows_the_unsaved_changes: the status reads differently while changes wait and once they are saved, differs again for a workbook with no file, and is absent while AutoSave is off.
  • closing_with_autosave_saves_instead_of_asking (tests/it/file_menu.rs): with AutoSave on, closing the window writes the change to the file and closes without asking; a new workbook without a file is still asked about.
  • closing_a_workbook_window_with_autosave_saves_instead_of_asking (tests/it/file_menu.rs): window.close on a workbook with AutoSave on writes the change and closes it without asking.

Changed:

  • a_logic_only_tick_autosaves_a_dirty_workbook_once backdates the batch past the 30 s delay instead of last_autosave past 2 s. It checks the same thing.
  • autosave_survives_a_restart gives its workbook an .xlsx path first, since AutoSave now turns on only for a workbook with a file.

Verification

Local run on Linux (CachyOS, Hyprland/Wayland), rustc 1.100.0, on top of main 3bed16a:

  • cargo test -p gridcraft-ui-egui --no-fail-fast: every binary passes except 2 tests in tests/it, interaction::column_autocomplete_folds_case_beyond_ascii and interaction::language_switch_renders_the_ribbon_and_persists. They panic with "No glyph for ẞ" because this machine has no CRAFT_FONTS_DIR. They fail the same way on main without this change.
  • With the old toggle_autosave put back, turning_autosave_on_asks_to_save_a_workbook_without_a_file fails. Without the open_dialog change, closing_a_workbook_window_with_autosave_saves_instead_of_asking fails.
  • cargo clippy -p gridcraft-ui-egui --all-targets -- -D warnings: clean.
  • cargo fmt --all -- --check: clean.
  • cargo xtask layers, cargo xtask assets, cargo xtask wasm, cargo xtask parity (no change to docs/parity-checklist.md), cargo xtask i18n-report: ran, no errors.
  • Desktop app on Linux, by hand: turning the switch on for a new workbook asks where to save and cancelling leaves it off; a single change is saved after about 30 s; the status follows the changes; closing a workbook with AutoSave on closes without asking and the change is in the file.
  • Not done: macOS and Windows builds.

New user-facing strings are in English only, through the translation system. The switch's label and tooltip are unchanged.

Accessibility

No new control. The switch and the Options checkbox are the same widgets. The status next to the switch is a plain text label in the title bar's dim text colour, read by screen readers, and it doesn't rely on colour. The new messages use the existing message box, which is reachable and dismissible by keyboard.

🤖 Generated with Claude Code

…ave on close (storytold#4847)

Turning AutoSave on for a workbook without an .xlsx file runs Save As
first; AutoSave turns on only once the workbook has a file, and the
switch shows on only when AutoSave can save the active workbook.

Unsaved changes are saved in batches: after 10 changes, or 30 s after
the first unsaved change. A failed save turns AutoSave off and says why.
Closing a workbook or quitting with AutoSave on saves it instead of
asking. The title bar shows Saving…, Saved or Not saved to a file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 27, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AutoSave switch turns on for a workbook with no file and then never saves; it should ask where to save first, and save changes in batches

1 participant