diff --git a/crates/ui-egui/src/dialogs/simplify_slider.rs b/crates/ui-egui/src/dialogs/simplify_slider.rs index 23ed5cfa85..cb58f856a7 100644 --- a/crates/ui-egui/src/dialogs/simplify_slider.rs +++ b/crates/ui-egui/src/dialogs/simplify_slider.rs @@ -86,7 +86,7 @@ pub(crate) struct Strip { /// Which command the strip previews. pub kind: StripKind, /// The drawing whose selection and preview the strip uses. - document: Option, + document: Option<(u64, u64)>, /// The slider's value, 0 to 100. pub level: f64, /// The selection's document bounds when the strip opened, so the strip stays put while the @@ -102,7 +102,7 @@ pub(crate) struct Strip { impl Strip { fn in_source(&self, app: &VectorcraftApp) -> bool { - self.document == app.session.active().map(|doc| doc.uid) + self.document == app.session.active().map(|doc| (doc.uid, doc.reverts)) } fn cancel(self, app: &mut VectorcraftApp) { @@ -142,7 +142,7 @@ pub(crate) fn open(app: &mut VectorcraftApp, kind: StripKind) { } let strip = Strip { kind, - document: app.session.active().map(|doc| doc.uid), + document: app.session.active().map(|doc| (doc.uid, doc.reverts)), level: opening_level(app, kind), bounds: app.selection_bounds(), open: true, diff --git a/crates/ui-egui/src/dialogs/tests_modal.rs b/crates/ui-egui/src/dialogs/tests_modal.rs index 8fd5193074..e9a2166fa7 100644 --- a/crates/ui-egui/src/dialogs/tests_modal.rs +++ b/crates/ui-egui/src/dialogs/tests_modal.rs @@ -293,3 +293,36 @@ fn simplify_slider_and_dialog_simplify_only_the_direct_selected_part_of_a_path() assert_eq!(app.session.doc().unwrap().history.undo.len(), undo_len + 1); kept(&app, "the dialog"); } + +#[test] +fn path_sliders_close_when_file_revert_restores_the_artwork() { + for (kind, command) in + [(simplify_slider::StripKind::Simplify, "object.path.simplify"), (simplify_slider::StripKind::Smooth, "object.path.smooth")] + { + let mut app = app_with_dense_path(); + let id = app.session.active().unwrap().selection.objects[0]; + let dir = vectorcraft_testkit::TempDir::new("path-slider-revert"); + app.services.read = Some(Box::new(|path| std::fs::read(path).map_err(|e| e.to_string()))); + app.services.write = Some(Box::new(|path, bytes| std::fs::write(path, bytes).map_err(|e| e.to_string()))); + app.run("file.saveAs", json!({"path": dir.join("Art.vectorcraft")})).unwrap(); + app.run("object.move", json!({"dx": 10, "dy": 0})).unwrap(); + app.run("select.anchors", json!({"id": id.0, "anchors": [[0, 19]]})).unwrap(); + crate::menus::invoke(&mut app, command, json!({})); + settle(&mut app); + assert!(simplify_slider::showing_of(&app, kind)); + assert!(app.session.in_interaction()); + + app.run("file.revert", json!({"confirmed": true})).unwrap(); + app.run("select.anchors", json!({"id": id.0, "anchors": [[0, 19]]})).unwrap(); + let restored = app.session.active().unwrap().doc.clone(); + frame(&mut app, vec![]); + assert!(!simplify_slider::showing_of(&app, kind), "{command}"); + assert!(!app.session.in_interaction()); + assert_eq!(app.session.active().unwrap().doc, restored); + + crate::menus::invoke(&mut app, command, json!({})); + settle(&mut app); + assert!(simplify_slider::showing_of(&app, kind)); + assert!(app.session.in_interaction()); + } +}