Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

Integration: #1416 Clear acts on live points only; reset anchor_release on press

aionggf3e0f614fd8e
diff --git a/crates/engine/src/cmd/anchors.rs b/crates/engine/src/cmd/anchors.rs
index 9d65098e6..46ec6c9e7 100644
--- a/crates/engine/src/cmd/anchors.rs
+++ b/crates/engine/src/cmd/anchors.rs
@@ -593,6 +593,21 @@ mod tests {
assert_eq!(s.doc().unwrap().doc.item(ItemId(a)).unwrap().path.subpaths[0].anchors.len(), 3, "one point gone, the frame stays");
}
+ /// Shift-adding an object to a point selection drops the points, so Clear deletes the objects.
+ #[test]
+ fn clear_after_adding_an_object_to_a_point_selection_deletes_objects() {
+ let mut s = Session::new();
+ s.execute("file.new", &json!({})).unwrap();
+ let a = s.execute("frame.create", &json!({"rect": [72, 72, 172, 172]})).unwrap()["id"].as_u64().unwrap();
+ let b = s.execute("frame.create", &json!({"rect": [200, 72, 300, 172]})).unwrap()["id"].as_u64().unwrap();
+ s.execute("selection.set", &json!({"anchors": [[a, 0, 0]]})).unwrap();
+ s.execute("selection.set", &json!({"ids": [b], "add": true})).unwrap();
+ assert!(s.doc().unwrap().selection.anchors.is_empty());
+ s.execute("edit.clear", &json!({})).unwrap();
+ assert!(s.doc().unwrap().doc.item(ItemId(a)).is_none());
+ assert!(s.doc().unwrap().doc.item(ItemId(b)).is_none());
+ }
+
#[test]
fn convert_point_kinds() {
let mut s = Session::new();
diff --git a/crates/engine/src/cmd/edit.rs b/crates/engine/src/cmd/edit.rs
index 34611c9e2..37ab535cb 100644
--- a/crates/engine/src/cmd/edit.rs
+++ b/crates/engine/src/cmd/edit.rs
@@ -263,6 +263,11 @@ pub fn specs() -> Vec<CommandSpec> {
}
let ids: Vec<ItemId> = ids.into_iter().filter(|i| st.doc.item(*i).is_some()).collect();
if add {
+ // Adding objects (no points) leaves no live points: Delete would otherwise remove
+ // the stale points instead of the objects.
+ if anchors.is_empty() {
+ st.selection.anchors.clear();
+ }
for i in ids {
if !st.selection.items.contains(&i) {
st.selection.items.push(i);
@@ -296,6 +301,7 @@ pub fn specs() -> Vec<CommandSpec> {
}
} else {
st.selection.items.push(id);
+ st.selection.anchors.clear();
}
st.bump_revision();
ok()
diff --git a/crates/tools/src/select.rs b/crates/tools/src/select.rs
index 94e8e2eaf..1fb30e6f7 100644
--- a/crates/tools/src/select.rs
+++ b/crates/tools/src/select.rs
@@ -792,6 +792,7 @@ impl SelectionTool {
self.shift_release = None;
self.key_release = None;
+ self.anchor_release = None;
// Type on a path: a bracket moves where the text starts or ends.
if !ev.mods.shift
&& let Some((id, end)) = self.bracket_at(cx, p)