PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Pen resume: a stale draft joins its source path; undo stops at its anchors
Hector Villarreal199b0a122c1c
diff --git a/crates/ui-egui/src/pen_variants_tests.rs b/crates/ui-egui/src/pen_variants_tests.rsindex 1f786c939..257e4f591 100644--- a/crates/ui-egui/src/pen_variants_tests.rs+++ b/crates/ui-egui/src/pen_variants_tests.rs@@ -231,4 +231,29 @@ fn a_resumed_subpath_keeps_its_operation_and_a_stale_draft_adds_a_new_one() {let work = work_path(&app);assert_eq!(work.subpaths.len(), 2, "a new subpath, the replaced one untouched");assert_eq!(work.subpaths[0].knots.iter().map(|k| k.anchor.x).collect::<Vec<_>>(), [120.0, 180.0]);+ // The same with nothing selected in the Paths panel: still added to the Work Path it came from.+ click(&mut app, 180.0, 20.0);+ click(&mut app, 180.0, 90.0);+ app.ui.selected_path = None;+ app.run("path.set", json!({"name": "work", "path": {"subpaths": [open(120.0, 160.0, "combine")]}})).unwrap();+ crate::vector_ui::pen_commit(&mut app, false);+ assert_eq!(work_path(&app).subpaths.len(), 2, "added, not replacing the Work Path");+}++/// #6593 review: undoing points in a resumed draft never removes the path's own anchors; past the+/// added ones it drops the draft and the path stays as it was.+#[test]+fn undo_in_a_resumed_draft_stops_at_the_paths_own_anchors() {+ let mut app = app(Tool::Pen);+ click(&mut app, 20.0, 20.0);+ click(&mut app, 80.0, 20.0);+ crate::vector_ui::pen_commit(&mut app, false);+ let before = work_path(&app);+ click(&mut app, 80.0, 20.0);+ click(&mut app, 80.0, 80.0);+ assert!(crate::vector_ui::pen_undo_last_point(&mut app), "takes back the added anchor");+ assert_eq!(app.ui.pen.as_ref().map(|p| p.knots.len()), Some(2));+ assert!(crate::vector_ui::pen_undo_last_point(&mut app), "drops the draft");+ assert!(app.ui.pen.is_none());+ assert_eq!(work_path(&app), before, "the path is as it was");}diff --git a/crates/ui-egui/src/vector_ui.rs b/crates/ui-egui/src/vector_ui.rsindex 566164e5c..0161703c8 100644--- a/crates/ui-egui/src/vector_ui.rs+++ b/crates/ui-egui/src/vector_ui.rs@@ -308,6 +308,12 @@ fn shift_45(origin: [f64; 2], p: [f64; 2], shift: bool) -> [f64; 2] {/// knot rather than undoing an unrelated, already committed document operation.pub fn pen_undo_last_point(app: &mut PhotocraftApp) -> bool {let Some(pen) = app.ui.pen.as_mut() else { return false };+ // A resumed path's own anchors are not the draft's to take back: undoing past the ones added+ // since it resumed drops the draft and leaves the path as it was (#6593).+ if pen.resumes.as_ref().is_some_and(|r| pen.knots.len() <= r.was.knots.len()) {+ app.ui.pen = None;+ return true;+ }if pen.knots.pop().is_none() {return false;}@@ -492,7 +498,11 @@ fn commit_path(app: &mut PhotocraftApp, pen: &PenPath, closed: bool) {// Photoshop adds the new subpath to the path selected in the Paths panel, which is the// Work Path right after drawing one, so path after path builds up there (#4721). With no// path selected, a new Work Path replaces the old one. The drawn path ends up selected.- let target = app.ui.selected_path.clone().filter(|n| app.session.active().is_some_and(|st| path_exists(&st.doc, n)));+ // A resumed draft whose subpath changed meanwhile joins the path it came from, as a new+ // subpath, even with nothing selected in the Paths panel.+ let exists = |n: &String| app.session.active().is_some_and(|st| path_exists(&st.doc, n));+ let resumed_from = pen.resumes.as_ref().filter(|r| app.session.active().is_some_and(|st| st.doc.id.0 == r.doc)).map(|r| r.path.clone());+ let target = app.ui.selected_path.clone().filter(exists).or_else(|| resumed_from.filter(exists));let name = target.clone().unwrap_or_else(|| "work".into());let mut params = json!({"name": name, "path": path});if target.is_some() {