From b3a0b77679b48bdd4ea3e405f59f1c3d325c7498 Mon Sep 17 00:00:00 2001 From: dholzric Date: Mon, 30 Nov 2026 13:07:42 -0600 Subject: [PATCH] Stack Mode: name each mode's History state "Rendering Image Stack " (#18295) Layer > Smart Objects > Stack Mode recorded a mode as "Stack Mode: ". The reference application names the state "Rendering Image Stack ", with the entry's menu label. None keeps "Stack Mode: None". The stack mode entries in atn_cmds/events.rs are unchanged: actions find these steps by command id and event name, not by the History name. Co-Authored-By: Claude Fable 5.2 --- crates/engine-core/src/cmd/layer_menu_cmds.rs | 7 +- .../stack_mode_history_tests.rs | 71 +++++++++++++++++++ 2 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 crates/engine-core/src/cmd/layer_menu_cmds/stack_mode_history_tests.rs diff --git a/crates/engine-core/src/cmd/layer_menu_cmds.rs b/crates/engine-core/src/cmd/layer_menu_cmds.rs index 0beb4ccd56..5126723d52 100644 --- a/crates/engine-core/src/cmd/layer_menu_cmds.rs +++ b/crates/engine-core/src/cmd/layer_menu_cmds.rs @@ -393,8 +393,9 @@ fn color_decontaminate(s: &mut Session, p: &Value) -> Result { fn stack_mode(s: &mut Session, p: &Value, mode: Option) -> Result { let id = layer_param(s, p)?; - let label = mode.map_or("None", StackMode::label); - s.edit(&format!("Stack Mode: {label}"), |doc, _| { + // The History state of a mode is named after the rendering, with the entry's label; None keeps its own (#18295). + let name = mode.map_or_else(|| "Stack Mode: None".to_string(), |mode| format!("Rendering Image Stack {}", mode.label())); + s.edit(&name, |doc, _| { let l = doc.layer_mut(id).ok_or(EngineError::NoLayer(id))?; let LayerContent::Smart(sm) = &mut l.content else { return Err(other("the active layer is not a smart object")); @@ -1158,4 +1159,6 @@ pub fn specs() -> Vec { #[cfg(test)] mod global_light_background_only_tests; #[cfg(test)] +mod stack_mode_history_tests; +#[cfg(test)] mod tests; diff --git a/crates/engine-core/src/cmd/layer_menu_cmds/stack_mode_history_tests.rs b/crates/engine-core/src/cmd/layer_menu_cmds/stack_mode_history_tests.rs new file mode 100644 index 0000000000..5aa091e92b --- /dev/null +++ b/crates/engine-core/src/cmd/layer_menu_cmds/stack_mode_history_tests.rs @@ -0,0 +1,71 @@ +//! #18295: each Layer › Smart Objects › Stack Mode entry adds one History state named "Rendering Image Stack ", +//! as the reference application names it, instead of "Stack Mode: ". None keeps "Stack Mode: None". + +use photocraft_geom::Rect; +use serde_json::json; + +use crate::Session; + +/// The command's last id segment and the History state the reference application records for it. +const NAMES: [(&str, &str); 11] = [ + ("entropy", "Rendering Image Stack Entropy"), + ("kurtosis", "Rendering Image Stack Kurtosis"), + ("maximum", "Rendering Image Stack Maximum"), + ("mean", "Rendering Image Stack Mean"), + ("median", "Rendering Image Stack Median"), + ("minimum", "Rendering Image Stack Minimum"), + ("range", "Rendering Image Stack Range"), + ("skewness", "Rendering Image Stack Skewness"), + ("standardDeviation", "Rendering Image Stack Standard Deviation"), + ("summation", "Rendering Image Stack Summation"), + ("variance", "Rendering Image Stack Variance"), +]; + +/// A document whose active layer is a smart object. +fn smart_object() -> Session { + let mut s = crate::session(); + s.execute("file.new", json!({"width": 16, "height": 12})).unwrap(); + s.execute("layer.new.layer", json!({})).unwrap(); + s.edit("paint", |doc, active| { + doc.layer_mut(active.unwrap()).unwrap().surface_mut().unwrap().fill_rect(Rect::new(2, 2, 10, 8), &[1.0, 0.0, 0.0, 1.0]); + Ok(()) + }) + .unwrap(); + s.execute("layer.smartObjects.convertToSmartObject", json!({})).unwrap(); + s +} + +/// How many History states there are, and the name of the newest. +fn history(s: &Session) -> (usize, Option) { + let history = &s.active().unwrap().history; + (history.past_len(), history.undo_label().map(String::from)) +} + +#[test] +fn each_mode_adds_one_state_named_rendering_image_stack_and_its_entry() { + let mut s = smart_object(); + for (kind, name) in NAMES { + let states = history(&s).0; + s.execute(&format!("layer.smartObjects.stackMode.{kind}"), json!({})).unwrap(); + assert_eq!(history(&s), (states + 1, Some(name.to_string())), "{kind}"); + } +} + +/// The name follows the entry as the menu shows it. +#[test] +fn the_name_ends_with_the_entrys_menu_label() { + let _session = crate::session(); + for (kind, name) in NAMES { + let label = crate::commands::find(&format!("layer.smartObjects.stackMode.{kind}")).unwrap().label; + assert_eq!(name.strip_prefix("Rendering Image Stack "), Some(label), "{kind}"); + } +} + +#[test] +fn none_keeps_its_name() { + let mut s = smart_object(); + s.execute("layer.smartObjects.stackMode.median", json!({})).unwrap(); + let states = history(&s).0; + s.execute("layer.smartObjects.stackMode.none", json!({})).unwrap(); + assert_eq!(history(&s), (states + 1, Some("Stack Mode: None".to_string()))); +}