From 9f6be3c2a5b8ec0aa23e689c2580bc761cddc17c Mon Sep 17 00:00:00 2001 From: Mex <44814932+MMexicann@users.noreply.github.com> Date: Sat, 21 Nov 2026 18:16:04 +0100 Subject: [PATCH] fix(updater): check all tabs for unsaved work Add a test to ensure unsaved changes in inactive documents prevent installation. --- src/updates.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/updates.rs b/src/updates.rs index 5c06df8a..2da3c26f 100644 --- a/src/updates.rs +++ b/src/updates.rs @@ -18,7 +18,7 @@ fn stable_choice() -> Result<(), String> { /// Whether an update may close the editor without losing pending document work. pub(crate) fn safe_to_install(app: &crate::app::App) -> bool { - !app.s.is_dirty() + !crate::tabs::any_dirty(app) && !app.s.in_gesture() && !app.playing && app.text_edit.is_none() @@ -412,6 +412,21 @@ mod tests { updates.finish(); updates.apply_outcome(None); } + #[test] + fn unsaved_inactive_documents_prevent_installation() { + let ctx = egui::Context::default(); + let session = anicraft_engine::Session::new(anicraft_engine::doc::sample::demo()); + let mut app = crate::app::App::with_context(&ctx, session, Some(std::path::PathBuf::from("unused.png"))); + assert!(safe_to_install(&app)); + + assert!(app.run("draw.rect", serde_json::json!({"x": 0, "y": 0, "w": 10, "h": 10})).is_some()); + assert!(app.perform("file.new", serde_json::json!({})).is_some()); + + assert_eq!(app.tabs.len(), 2); + assert!(!app.s.is_dirty(), "the active document is clean"); + assert!(!safe_to_install(&app), "the inactive document has unsaved changes"); + } + #[test] fn uncommitted_stage_text_and_pen_paths_prevent_installation() { let ctx = egui::Context::default();