PhotoCraft: An open-source, photo editor written by scratch in pure Rust
fix(pen): keep unfinished paths in their original document (#5460)
Nigel Ihza Firdausy9b59a8ca6e0b
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rsindex 5929e9338..32a396234 100644--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@ -1086,6 +1086,10 @@ impl PhotocraftApp {id,"layer.vectorMask.add" | "layer.vectorMask.fromPath" | "layer.vectorMask.revealAll" | "layer.vectorMask.hideAll" | "layer.vectorMask.currentPath") && on_active_layer;+ // A draft Pen path belongs to the current document, not the one about to be created.+ if id == "file.new" && self.ui.pen.is_some() {+ vector_ui::pen_commit(self, false);+ }let r = if id == "actions.play" {actions::play(self, ¶ms)} else if photocraft_engine::actions_cmds::shell_view_command(id) {diff --git a/crates/ui-egui/src/pen_draw_tests.rs b/crates/ui-egui/src/pen_draw_tests.rsindex 74689a107..d8bb39d82 100644--- a/crates/ui-egui/src/pen_draw_tests.rs+++ b/crates/ui-egui/src/pen_draw_tests.rs@@ -122,6 +122,23 @@ fn alt_breaks_the_handle_being_dragged_and_grabs_the_last_outgoing_handle() {assert!(near([k.out_ctrl.x, k.out_ctrl.y], [140.0, 20.0]));}+#[test]+fn opening_a_new_document_finishes_the_previous_pen_path() {+ let mut h = harness();+ click(&mut h, [20.0, 20.0]);+ click(&mut h, [120.0, 20.0]);+ assert_eq!(h.state().ui.pen.as_ref().map(|p| p.knots.len()), Some(2));+ let original = h.state().session.active().unwrap().doc.id;++ h.state_mut().run("file.new", json!({"width": 300, "height": 200})).unwrap();+ assert!(h.state().ui.pen.is_none(), "the Pen draft must not overlay the new document");+ let docs = h.state().session.documents();+ assert_eq!(docs.len(), 2);+ assert_eq!(docs[0].doc.id, original);+ assert_eq!(docs[0].doc.work_path.as_ref().unwrap().subpaths[0].knots.len(), 2);+ assert!(docs[1].doc.work_path.is_none(), "the new document starts with no path");+}+#[test]fn dragging_on_the_first_anchor_closes_with_its_handles_in_one_step() {let mut h = harness();