diff --git a/src/updates.rs b/src/updates.rs index 4d449999..44c4058b 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() @@ -413,6 +413,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();