Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Expand New Effects follows the destination of Transfer Effects

abc2cb957e68f600fb
diff --git a/crates/engine/src/jobs.rs b/crates/engine/src/jobs.rs
index 5566d39c3..590a1a77c 100644
--- a/crates/engine/src/jobs.rs
+++ b/crates/engine/src/jobs.rs
@@ -727,8 +727,14 @@ impl Session {
// desktop UI normally calls `start`, even for synchronous Layer Style commands.
// The layer the command will change, named as the command accepts it (id or name), else the
// active one. `layer.layerStyle.clear` needs no case: it leaves no effects, so nothing expands.
+ // Transfer Effects changes its destination (`to`), not the layer it takes the effects from.
let new_fx_target = if id.starts_with("layer.layerStyle.") {
- let target = crate::commands::layer_param(self, &params).ok();
+ let target = if id == "layer.layerStyle.transferEffects" {
+ crate::commands::layer_param(self, &json!({"layer": params.get("to").cloned().unwrap_or(Value::Null)}))
+ } else {
+ crate::commands::layer_param(self, &params)
+ }
+ .ok();
self.active().and_then(|st| {
let target = target?;
(st.doc.layer(target)?.effects.items.is_empty()).then_some((st.doc.id, target))
diff --git a/crates/engine/src/layer_multi_cmds.rs b/crates/engine/src/layer_multi_cmds.rs
index 2705077d6..935559192 100644
--- a/crates/engine/src/layer_multi_cmds.rs
+++ b/crates/engine/src/layer_multi_cmds.rs
@@ -3013,4 +3013,19 @@ mod layers_panel_parity_tests {
assert!(s.active().unwrap().fx_collapsed.contains(&named), "the named layer's new effects start collapsed");
assert!(!s.active().unwrap().fx_collapsed.contains(&active), "the active layer is not the one changed");
}
+
+ /// Transfer Effects changes the layer it moves the effects to, so that is the layer whose
+ /// disclosure follows the option, not the active layer or the one the effects came from.
+ #[test]
+ fn expand_new_effects_follows_the_transfer_destination() {
+ let (mut s, ids) = new_session();
+ let (from, to, active) = (ids[0], ids[1], ids[2]);
+ s.execute("layer.layerStyle.dropShadow", json!({"layer": from.0, "size": 2})).unwrap();
+ option(&mut s, "expandNewEffects", false);
+ assert_eq!(s.active().unwrap().active_layer, Some(active));
+ s.execute("layer.layerStyle.transferEffects", json!({"from": from.0, "to": to.0, "copy": true})).unwrap();
+ assert!(s.active().unwrap().doc.layer(to).is_some_and(|l| !l.effects.items.is_empty()));
+ assert!(s.active().unwrap().fx_collapsed.contains(&to), "the destination's new effects start collapsed");
+ assert!(!s.active().unwrap().fx_collapsed.contains(&active), "the active layer is not the one changed");
+ }
}