Appearance: effect.move's reply follows an explicit toItem to the first target

This commit is contained in:
dotCooCoo
2026-11-02 12:04:10 +07:00
committed by bflatastic
parent 468102e101
commit e4a066f12a
2 changed files with 13 additions and 4 deletions
+4 -4
View File
@@ -325,10 +325,10 @@ fn move_effect(s: &mut Session, p: &Value) -> Result<Value> {
}
Ok(done)
})?;
// The reply names the object whose row the active item is (the first selected object, which
// need not paint first), as `effect.apply` does; the first target otherwise.
let anchor = if matches!(src, ItemTarget::Item { explicit: false, .. }) { src } else { dst };
let (index, item) = landed.get(anchor.anchor(s, &ids)).copied().unzip();
// The reply names the object whose row the destination is: the first selected object for the
// active item (which need not paint first), as `effect.apply` does; the first target for an
// explicit `toItem` or the object's effects.
let (index, item) = landed.get(dst.anchor(s, &ids)).copied().unzip();
Ok(json!({ "ids": ids_json(&ids), "index": index, "item": item.flatten() }))
}
+9
View File
@@ -560,6 +560,15 @@ fn move_reports_the_index_in_the_object_whose_row_it_names() {
let r = run(&mut s, "effect.move", json!({"from": 1, "to": 0}));
assert_eq!(r["ids"], json!([b.0]), "only b has a second effect in row 0");
assert_eq!((r["item"].clone(), r["index"].clone()), (json!(0), json!(0)), "b's effect moved to the start of its row 0");
// From the active row to an explicit destination (here the object's effects, where b already
// has one), the reply names the first target, a.
run(&mut s, "select.set", json!({"ids": [b.0]}));
run(&mut s, "effect.apply", json!({"effect": "distort.twist", "item": null}));
run(&mut s, "select.set", json!({"ids": [b.0, a.0]}));
run(&mut s, "appearance.setActiveItem", json!({"index": 0}));
let r = run(&mut s, "effect.move", json!({"from": 0, "to": 9, "toItem": null}));
assert_eq!((node(&s, a).appearance.effects.len(), node(&s, b).appearance.effects.len()), (1, 2));
assert_eq!((r["item"].clone(), r["index"].clone()), (json!(null), json!(0)), "a's effects hold one effect");
}
/// How many steps there are to undo and to redo, and whether the document has unsaved changes.