Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Pen resume: a stale draft prefers the path it came from over the selected one

Hector Villarreal060a8cced717
diff --git a/crates/ui-egui/src/pen_variants_tests.rs b/crates/ui-egui/src/pen_variants_tests.rs
index f82d049ea..cee8e37bb 100644
--- a/crates/ui-egui/src/pen_variants_tests.rs
+++ b/crates/ui-egui/src/pen_variants_tests.rs
@@ -238,6 +238,17 @@ fn a_resumed_subpath_keeps_its_operation_and_a_stale_draft_adds_a_new_one() {
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");
+ // And with another path selected: the draft still goes back to the path it came from.
+ app.run("path.set", json!({"name": "Other", "path": {"subpaths": [open(10.0, 30.0, "combine")]}})).unwrap();
+ click(&mut app, 160.0, 20.0);
+ click(&mut app, 160.0, 90.0);
+ app.ui.selected_path = Some("Other".into());
+ app.run("path.set", json!({"name": "work", "path": {"subpaths": [open(120.0, 150.0, "combine")]}})).unwrap();
+ crate::vector_ui::pen_commit(&mut app, false);
+ assert_eq!(work_path(&app).subpaths.len(), 2, "joined the Work Path it came from");
+ let st = app.session.active().unwrap();
+ let other = st.doc.paths.iter().find(|p| p.name == "Other").unwrap();
+ assert_eq!(other.path.subpaths.len(), 1, "the selected path is untouched");
}
/// #6593 review: undoing points in a resumed draft never removes the path's own anchors; past the
diff --git a/crates/ui-egui/src/vector_ui.rs b/crates/ui-egui/src/vector_ui.rs
index 8a18ad8f4..f693fa8d7 100644
--- a/crates/ui-egui/src/vector_ui.rs
+++ b/crates/ui-egui/src/vector_ui.rs
@@ -506,7 +506,7 @@ fn commit_path(app: &mut PhotocraftApp, pen: &PenPath, closed: bool) {
// 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 target = resumed_from.filter(exists).or_else(|| app.ui.selected_path.clone().filter(exists));
let name = target.clone().unwrap_or_else(|| "work".into());
let mut params = json!({"name": name, "path": path});
if target.is_some() {