Smart Objects: stacked layers sit at the contents top level (#2657) (#2676)

* Smart Objects: converting several layers keeps them at the contents top level (#2648)

Convert to Smart Object with several selected layers wrapped them in a
temporary group before embedding, so Edit Contents showed one group named
after the top layer. Photoshop puts the selected layers at the top level of
the embedded document. The embedding now goes through layers_to_smart, which
takes the layers directly; a pass-through root composites the same, so the
smart object looks unchanged. A single selected group still converts as is.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Smart Objects: stacked layers sit at the contents top level (#2657)

Load Files into Stack with Create Smart Object, and Statistics with
alignment, put the loaded layers in a temporary group before embedding,
so the smart object's contents held one group named after the first file.
Photoshop puts one layer per file at the top level of the contents. Both
call sites now pass the layers to layers_to_smart. The wrapper was an
opaque Normal group of opaque Normal layers, so the composite is the same.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Valentin KleinandClaude Opus 5.5 authored and GitHub committed 2026-10-10 16:17:49 -04:00
1 parent 5d9e812efc
commit dfa4a2e51e
3 files changed
+43 -7

No files matched your search

+2 -3
View File
@@ -379,9 +379,8 @@ fn statistics(s: &mut Session, p: &Value) -> Result<Value> {
s.execute("edit.autoAlignLayers", json!({"projection": "auto"}))?;
let name = s.active().map(|d| d.doc.name.clone()).unwrap_or_default();
s.edit("Convert to Smart Object", |doc, active| {
let children = std::mem::take(&mut doc.layers);
let group = Layer::new(name.clone(), LayerContent::Group(photocraft_doc::Group { children, expanded: true, artboard: None }));
let smart = crate::smart_cmds::layer_to_smart(doc, &group)?;
let layers = std::mem::take(&mut doc.layers);
let smart = crate::smart_cmds::layers_to_smart(doc, &name, layers)?;
*active = Some(smart.id);
doc.layers = vec![smart];
Ok(())
+37
View File
@@ -130,6 +130,43 @@ fn statistics_makes_a_stack_mode_smart_object() {
assert!(s.execute("file.scripts.statistics", json!({"mode": "average", "input": dir})).is_err());
}
#[test]
fn stacked_smart_object_holds_the_loaded_layers_at_its_top_level() {
// Like Photoshop, Load Files into Stack › Create Smart Object (Statistics without alignment) and
// Statistics with alignment embed one layer per file, bottom to top, with no wrapper group.
let dir = tmp("stack-top");
let mut s = Session::new();
s.execute("file.new", json!({"width": 96, "height": 72, "background": "#606060"})).unwrap();
s.edit("texture", |doc, active| {
let surf = doc.layer_mut(active.ok_or(EngineError::NoDocument)?).and_then(Layer::surface_mut).ok_or(EngineError::NoDocument)?;
for k in 0..40 {
let (x, y, v) = ((k * 37) % 88, (k * 23) % 66, (k % 7) as f32 / 6.0);
surf.fill_rect(photocraft_geom::Rect::new(x, y, x + 3 + k % 5, y + 2 + k % 4), &[v, 1.0 - v, 0.5, 1.0]);
}
Ok(())
})
.unwrap();
let source = photocraft_compose::flatten(&s.active().unwrap().doc);
let files: Vec<String> = (0..3)
.map(|i| {
let path = format!("{dir}/img{i}.png");
crate::file_cmds::save_doc(&s.active().unwrap().doc, &path, None).unwrap();
path
})
.collect();
for align in [false, true] {
let mut s = Session::new();
s.execute("file.scripts.statistics", json!({"mode": "median", "input": files, "align": align})).unwrap();
let d = &s.active().unwrap().doc;
let LayerContent::Smart(so) = &d.layers[0].content else { panic!("not a smart object") };
let photocraft_doc::SmartSource::Embedded { file_name, bytes } = &so.source else { panic!("not embedded") };
let inner = crate::smart_cmds::decode_source(file_name, bytes).unwrap();
let names: Vec<&str> = inner.layers.iter().map(|l| l.name.as_str()).collect();
assert_eq!(names, ["img0.png", "img1.png", "img2.png"], "align {align}");
assert_eq!(photocraft_compose::flatten(d).px, source.px, "align {align}");
}
}
#[test]
fn contact_sheet_places_thumbnails_with_captions() {
let dir = tmp("contact");
+4 -4
View File
@@ -840,10 +840,10 @@ fn load_files_into_stack(s: &mut Session, p: &Value) -> Result<Value> {
let n = stack.layers.len();
if p.get("createSmartObject").and_then(Value::as_bool).unwrap_or(false) {
// "Create Smart Object after Loading Layers": the layers go inside one smart object, ready
// for Layer › Smart Objects › Stack Mode.
let children = std::mem::take(&mut stack.layers);
let group = Layer::new(stem(&paths[0]), LayerContent::Group(photocraft_doc::Group { children, expanded: true, artboard: None }));
let smart = crate::smart_cmds::layer_to_smart(&stack, &group)?;
// for Layer › Smart Objects › Stack Mode. Like Photoshop, they sit at the top level of the
// contents, with no wrapper group.
let layers = std::mem::take(&mut stack.layers);
let smart = crate::smart_cmds::layers_to_smart(&stack, &stem(&paths[0]), layers)?;
stack.layers = vec![smart];
}
let i = s.add_document(stack, None);