From 177db3650a22fde6f03fbae19170cba33fa86aee Mon Sep 17 00:00:00 2001 From: SBaksa <18648812+SBaksa@users.noreply.github.com> Date: Sun, 15 Nov 2026 04:36:00 +1100 Subject: [PATCH] Name the Artboard from Layers history step "New Artboard From Layers" (#14578) Adds a test at 8/16/32 bit that exactly one step with that name is added and a single undo restores the layer tree. --- crates/engine/src/cmd/artboard_cmds.rs | 5 ++- .../from_layers_history_name_tests.rs | 44 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 crates/engine/src/cmd/artboard_cmds/from_layers_history_name_tests.rs diff --git a/crates/engine/src/cmd/artboard_cmds.rs b/crates/engine/src/cmd/artboard_cmds.rs index 00b0f7e37f..e786286e4e 100644 --- a/crates/engine/src/cmd/artboard_cmds.rs +++ b/crates/engine/src/cmd/artboard_cmds.rs @@ -408,7 +408,7 @@ fn artboard_from_layers(s: &mut Session, p: &Value) -> Result { // A size of the user's own (a post, a story…) from the layers' top left; 0 or none keeps // their bounds on that axis (#9087). let size = [int(p, "width").filter(|v| *v != 0), int(p, "height").filter(|v| *v != 0)]; - let (gid, rect, shift) = s.edit("Artboard from Layers", |doc, active| { + let (gid, rect, shift) = s.edit("New Artboard From Layers", |doc, active| { let ids = crate::layer_multi_cmds::top_level(doc, &sel); if ids.is_empty() || ids.iter().any(|id| doc.artboard_of(*id).is_some()) { return Err(EngineError::Other("select layers that are not in an artboard".into())); @@ -848,5 +848,8 @@ pub fn specs() -> Vec { #[path = "artboard_cmds/first_board_background_tests.rs"] mod first_board_background_tests; #[cfg(test)] +#[path = "artboard_cmds/from_layers_history_name_tests.rs"] +mod from_layers_history_name_tests; +#[cfg(test)] #[path = "artboard_cmds/tests.rs"] mod tests; diff --git a/crates/engine/src/cmd/artboard_cmds/from_layers_history_name_tests.rs b/crates/engine/src/cmd/artboard_cmds/from_layers_history_name_tests.rs new file mode 100644 index 0000000000..34dbe6d306 --- /dev/null +++ b/crates/engine/src/cmd/artboard_cmds/from_layers_history_name_tests.rs @@ -0,0 +1,44 @@ +//! Artboard from Layers adds one history step named "New Artboard From Layers" (#14578). + +use super::*; +use photocraft_geom::Rect; + +/// 100 x 80 RGB at `depth` with a pixel layer "Red" holding a square at 10,10 to 30,30. +fn session(depth: u32) -> Session { + let mut s = Session::new(); + s.execute("file.new", json!({"width": 100, "height": 80, "depth": depth, "background": "white"})).unwrap(); + s.edit("Red", |doc, active| { + let fmt = doc.pixel_format(); + let mut l = Layer::raster("Red", fmt); + l.surface_mut().unwrap().fill_rect(Rect::new(10, 10, 30, 30), &photocraft_raster::from_rgba(&fmt, [1.0, 0.0, 0.0, 1.0])); + let id = doc.insert_above(None, l); + *active = Some(id); + Ok(id) + }) + .unwrap(); + s +} + +fn steps(s: &Session) -> Vec { + s.active().unwrap().history.entries() +} + +fn tree(s: &Session) -> Vec<(String, bool)> { + s.active().unwrap().doc.walk().iter().map(|(_, _, l)| (l.name.clone(), l.children().is_some())).collect() +} + +#[test] +fn artboard_from_layers_adds_one_new_artboard_from_layers_step() { + for depth in [8, 16, 32] { + let mut s = session(depth); + let before_steps = steps(&s); + let before_tree = tree(&s); + s.execute("layer.new.artboardFromLayers", json!({"name": "Board"})).unwrap(); + let after = steps(&s); + assert_eq!(after.len(), before_steps.len() + 1, "exactly one step at {depth} bit: {after:?}"); + assert_eq!(after.last().map(String::as_str), Some("New Artboard From Layers"), "{depth} bit"); + s.undo(); + assert_eq!(tree(&s), before_tree, "one undo restores the layer tree at {depth} bit"); + assert!(s.active().unwrap().doc.artboards().is_empty()); + } +}