diff --git a/crates/engine/src/cmd/actions_cmds.rs b/crates/engine/src/cmd/actions_cmds.rs index 69373aec6d..2e59e87fc3 100644 --- a/crates/engine/src/cmd/actions_cmds.rs +++ b/crates/engine/src/cmd/actions_cmds.rs @@ -859,7 +859,7 @@ pub fn moved_index(index: usize, from: usize, to: usize) -> usize { } } -/// Remove the resolved action while retaining the identities of unaffected definitions and calls. +/// Delete the selected set, action or step with the appropriate playback and recording guards. fn delete(s: &mut Session, p: &Value) -> Result { not_playing(s, "actions.delete")?; if p.get("set").is_some() { diff --git a/crates/engine/src/cmd/atn_cmds/steps_doc.rs b/crates/engine/src/cmd/atn_cmds/steps_doc.rs index ee80dafbdc..2c2badfc90 100644 --- a/crates/engine/src/cmd/atn_cmds/steps_doc.rs +++ b/crates/engine/src/cmd/atn_cmds/steps_doc.rs @@ -113,9 +113,20 @@ pub(super) fn conditional_from(d: &Descriptor) -> Mapped { _ => None, }; let mut params = json!({"if": condition, "then": branch("then"), "else": branch("else")}); - for key in ["then", "else"] { - if let Some(set) = get_ref(d, key).and_then(|reference| super::steps_layer::action_set(reference)) { - params[format!("{key}Set")] = json!(set); + let scopes = ["then", "else"].map(|key| (key, get_ref(d, key).and_then(|reference| super::steps_layer::action_set(reference)))); + let shared = scopes + .iter() + .filter(|(key, _)| params[*key].is_string()) + .find_map(|(_, set)| set.as_deref()) + .filter(|set| scopes.iter().all(|(key, scope)| !params[*key].is_string() || scope.as_deref() == Some(*set))); + if let Some(set) = shared { + // Preserve the existing command shape when every active branch has the same scope. + params["set"] = json!(set); + } else { + for (key, set) in scopes { + if let Some(set) = set { + params[format!("{key}Set")] = json!(set); + } } } step("actions.conditional", params) diff --git a/crates/engine/tests/it/atn_call_scopes.rs b/crates/engine/tests/it/atn_call_scopes.rs index 41dcf6c968..34cd5013bd 100644 --- a/crates/engine/tests/it/atn_call_scopes.rs +++ b/crates/engine/tests/it/atn_call_scopes.rs @@ -122,3 +122,16 @@ fn portable_conditional_branches_retain_independent_set_scopes() { assert_eq!(session.active().unwrap().doc.layers.last().unwrap().name, expected); } } + +/// Retaining set references must not invent per-branch fields for the existing shared-set API. +#[test] +fn portable_conditional_shared_scope_keeps_the_existing_command_shape() { + use photocraft_engine::atn_cmds; + for other in [serde_json::Value::Null, json!("Else")] { + let params = json!({"if":"always","then":"Then","else":other,"set":"S"}); + let action = Action::new("Caller", vec![("actions.conditional".into(), params.clone())]); + let bytes = atn_cmds::export("S", &[&action], &[], false).unwrap().0; + let imported = atn_cmds::import(&bytes).unwrap(); + assert_eq!(imported.actions[0].steps[0].1, params); + } +}