Integration: transform.move on content reports the ids it moved (#521)

#521 makes transform.move return {moved, ids}; next's move_content (the content-selection path, content?) returned only {moved}. It returns the ids of the items whose content or frame moved, and copies_report_their_ids checks it.
This commit is contained in:
aiongg
2026-10-11 19:11:53 +00:00
parent 3af8c6275d
commit 13fb00fd08
+4 -3
View File
@@ -1023,7 +1023,7 @@ fn linear_inverse(m: Affine, v: Vec2) -> Vec2 {
/// frame resize refits.
fn move_content(s: &mut Session, ids: &[ItemId], d: Vec2) -> Result<Value> {
s.edit(|doc, _| {
let mut moved = 0;
let mut moved = Vec::new();
for id in ids {
let loc = doc.find(*id).ok_or(designcraft_doc::DocError::NoItem(*id))?;
let parent = doc.parent_xf(&loc);
@@ -1043,9 +1043,9 @@ fn move_content(s: &mut Session, ids: &[ItemId], d: Vec2) -> Result<Value> {
}
_ => it.xf = Affine::translate(linear_inverse(parent, d)) * it.xf,
}
moved += 1;
moved.push(id.0);
}
Ok(json!({"moved": moved}))
Ok(json!({"moved": moved.len(), "ids": moved}))
})
}
@@ -3415,6 +3415,7 @@ mod copy_ids_tests {
let selected = |s: &crate::Session| s.doc().unwrap().selection.items.iter().map(|i| i.0).collect::<Vec<_>>();
// Moving reports what moved; copying reports the copies, which are selected.
assert_eq!(ids(&s.execute("transform.move", &json!({"dx": 5, "dy": 0, "ids": [a]})).unwrap()), [a]);
assert_eq!(ids(&s.execute("transform.move", &json!({"dx": 5, "dy": 0, "ids": [a], "content": true})).unwrap()), [a]);
let r = s.execute("transform.move", &json!({"dx": 100, "dy": 0, "copy": true, "ids": [a]})).unwrap();
let copy = ids(&r);
assert!(copy.len() == 1 && copy[0] != a && s.doc().unwrap().doc.item(designcraft_doc::ItemId(copy[0])).is_some(), "{r}");