Merge #14697 into the merge queue batch

Name the Artboard from Layers history step "New Artboard From Layers" (#14578)

# Conflicts:
#	crates/engine/src/cmd/artboard_cmds.rs
This commit is contained in:
David Mann committed 2026-11-20 15:06:08 +01:00
commit 7fbe96eaca
2 files changed
+49 -1

No files matched your search

+5 -1
View File
@@ -421,7 +421,7 @@ fn artboard_from_layers(s: &mut Session, p: &Value) -> Result<Value> {
// 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()));
@@ -1039,6 +1039,10 @@ mod file_names_tests;
#[cfg(test)]
#[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/from_group_hidden_bounds_tests.rs"]
mod from_group_hidden_bounds_tests;
@@ -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<String> {
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());
}
}