DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
fix(paths): Join Path with one of two paths locked refuses instead of closing the other
aionggc275878087ee
diff --git a/crates/engine/src/cmd/anchors.rs b/crates/engine/src/cmd/anchors.rsindex f2225c480..72b2f085b 100644--- a/crates/engine/src/cmd/anchors.rs+++ b/crates/engine/src/cmd/anchors.rs@@ -84,10 +84,11 @@ fn join_paths(s: &mut Session, p: &Value) -> Result<Value> {s.edit(|d, sel| {let paths: Vec<ItemId> = ids.iter().copied().filter(|id| d.item(*id).is_some_and(|it| !it.is_group() && it.text_frame().is_none())).collect();let ids: Vec<ItemId> = paths.iter().copied().filter(|id| path_editable(d, *id, "path.join").is_ok()).collect();- if ids.is_empty()- && let Some(id) = paths.first()- {- path_editable(d, *id, "path.join")?;+ // A request for two paths never falls back to closing the one that is editable.+ if ids.len() < paths.len().min(2) {+ for id in &paths {+ path_editable(d, *id, "path.join")?;+ }}let open = |d: &Document, id: ItemId| d.item(id).and_then(|it| it.path.subpaths.iter().position(|sp| !sp.closed && sp.anchors.len() > 1));match ids.as_slice() {diff --git a/crates/engine/src/cmd/object.rs b/crates/engine/src/cmd/object.rsindex a05024388..dd469d8aa 100644--- a/crates/engine/src/cmd/object.rs+++ b/crates/engine/src/cmd/object.rs@@ -3426,6 +3426,24 @@ mod path_edit_tests {assert_no_path_edit(&mut s, id, "on a locked layer");}+ #[test]+ fn joining_two_paths_with_one_on_a_locked_layer_changes_neither() {+ let (mut s, a) = session_with_path();+ let b = s.execute("path.create", &json!({"anchors": [{"p": [300, 200]}, {"p": [400, 300]}]})).unwrap()["id"].as_u64().unwrap();+ let layer = s.execute("layer.new", &json!({"name": "Art"})).unwrap()["id"].as_u64().unwrap();+ s.execute("object.setLayer", &json!({"ids": [b], "layer": layer})).unwrap();+ let a_layer = s.doc().unwrap().doc.item(ItemId(a)).unwrap().layer;+ s.execute("layer.set", &json!({"id": a_layer.0, "locked": true})).unwrap();+ let (before_a, before_b) = (anchors(&s, a), anchors(&s, b));+ for ids in [[a, b], [b, a]] {+ assert!(s.execute("path.join", &json!({"ids": ids})).is_err(), "{ids:?}");+ }+ assert_eq!((anchors(&s, a), anchors(&s, b)), (before_a, before_b));+ for id in [a, b] {+ assert!(!s.doc().unwrap().doc.item(ItemId(id)).unwrap().path.subpaths[0].closed, "{id} stays open");+ }+ }+#[test]fn path_edits_leave_a_path_in_a_locked_group_alone() {let (mut s, id) = session_with_path();