From 8893d1274f5d992f8981765fe272764ac3c7c4d2 Mon Sep 17 00:00:00 2001 From: NaufalDzz Date: Sat, 14 Nov 2026 21:22:58 +0000 Subject: [PATCH 1/2] Layers: Layer from Background makes a hidden Background visible (#14822) Converting a hidden Background through Layer > New > Layer from Background (also the row double-click and lock icon) now makes the new layer visible, as in the reference application. Undo brings back the hidden Background in one step. Implicit conversions through background_to_layer keep the layer's visibility. Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com> --- crates/engine/src/cmd/extra_cmds.rs | 6 ++ .../layer_from_background_visible_tests.rs | 55 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 crates/engine/src/cmd/layer_from_background_visible_tests.rs diff --git a/crates/engine/src/cmd/extra_cmds.rs b/crates/engine/src/cmd/extra_cmds.rs index 505048f6ae..fc19eb771c 100644 --- a/crates/engine/src/cmd/extra_cmds.rs +++ b/crates/engine/src/cmd/extra_cmds.rs @@ -495,6 +495,9 @@ fn layer_from_background(s: &mut Session, p: &Value) -> Result { let id = s.edit("Layer From Background", |doc, active| { let l = doc.background_mut().ok_or(EngineError::Other("the document has no Background layer".into()))?; unlock_background(l); + // Only this explicit conversion shows a hidden Background, as in the reference + // application; implicit ones through `background_to_layer` keep its visibility. + l.visible = true; if select || active.is_none() { *active = Some(l.id); } @@ -1196,5 +1199,8 @@ pub fn specs() -> Vec { ] } +#[cfg(test)] +#[path = "layer_from_background_visible_tests.rs"] +mod layer_from_background_visible_tests; #[cfg(test)] mod tests; diff --git a/crates/engine/src/cmd/layer_from_background_visible_tests.rs b/crates/engine/src/cmd/layer_from_background_visible_tests.rs new file mode 100644 index 0000000000..fa7053d600 --- /dev/null +++ b/crates/engine/src/cmd/layer_from_background_visible_tests.rs @@ -0,0 +1,55 @@ +//! Layer from Background on a hidden Background (#14822): the reference application makes the new +//! layer visible, and one undo brings the hidden Background back. Implicit conversions (an edit the +//! Background can't take) keep its visibility. + +use super::*; + +/// White Background (hidden when `hidden`) plus one normal layer above it. +fn session(hidden: bool) -> Session { + let mut s = Session::new(); + s.execute("file.new", json!({"width": 40, "height": 30})).unwrap(); + s.execute("layer.new.layer", json!({})).unwrap(); + let bg = background(&s).id; + s.execute("layer.setProps", json!({"layer": bg.0, "visible": !hidden})).unwrap(); + s +} + +fn background(s: &Session) -> &Layer { + &s.active().unwrap().doc.layers[0] +} + +#[test] +fn converting_a_hidden_background_makes_the_layer_visible() { + let mut s = session(true); + assert!(!background(&s).visible); + let h = s.active().unwrap().history.past_len(); + s.execute("layer.new.layerFromBackground", json!({})).unwrap(); + let l = background(&s); + assert_eq!(l.name, "Layer 0"); + assert!(l.visible, "the converted layer is visible"); + assert_eq!(s.active().unwrap().history.past_len(), h + 1, "one History step"); + + assert!(s.undo()); + let l = background(&s); + assert_eq!(l.name, "Background"); + assert!(!l.visible, "undo brings back the hidden Background"); + assert!(l.locks.transparency && l.locks.position, "with its locks"); +} + +#[test] +fn converting_a_visible_background_keeps_it_visible() { + let mut s = session(false); + s.execute("layer.new.layerFromBackground", json!({})).unwrap(); + assert!(background(&s).visible); +} + +#[test] +fn an_implicit_conversion_keeps_a_hidden_background_hidden() { + let mut s = session(true); + let bg = background(&s).id; + // A layer mask is something the Background can't take, so it becomes "Layer 0" first. + s.execute("layer.layerMask.revealAll", json!({"layer": bg.0})).unwrap(); + let l = background(&s); + assert_eq!(l.name, "Layer 0"); + assert!(!l.visible); +} From c33f75f6f44b939f084de7ca47c0f19514c9665c Mon Sep 17 00:00:00 2001 From: NaufalDzz Date: Sun, 15 Nov 2026 06:50:24 +0000 Subject: [PATCH 2/2] Layer from Background: an action's step keeps a hidden Background hidden An action's set step on the Background replays the conversion through the same command; it now passes show: false, so only the menu command, the double-click and the lock icon make a hidden Background visible (#14822 review). Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com> --- crates/engine/src/cmd/atn_cmds/steps_make.rs | 2 +- crates/engine/src/cmd/atn_cmds/tests.rs | 2 +- crates/engine/src/cmd/extra_cmds.rs | 9 +++++++-- .../src/cmd/layer_from_background_visible_tests.rs | 10 ++++++++++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/crates/engine/src/cmd/atn_cmds/steps_make.rs b/crates/engine/src/cmd/atn_cmds/steps_make.rs index 0e16f09c8f..477341fa3f 100644 --- a/crates/engine/src/cmd/atn_cmds/steps_make.rs +++ b/crates/engine/src/cmd/atn_cmds/steps_make.rs @@ -997,7 +997,7 @@ fn background_from(d: &Descriptor) -> Mapped { // On an image that opened as a normal layer there is no Background to convert; // Photoshop stops there, but the step's purpose (an editable layer) is met. // Photoshop's `set` of another layer doesn't target it: the selected layer stays. - let mut v = vec![("layer.new.layerFromBackground", json!({"ifPresent": true, "select": false}))]; + let mut v = vec![("layer.new.layerFromBackground", json!({"ifPresent": true, "select": false, "show": false}))]; let mut props = Map::new(); props.insert("layer".into(), "Layer 0".into()); if let Some(t) = get_obj(d, "T ") { diff --git a/crates/engine/src/cmd/atn_cmds/tests.rs b/crates/engine/src/cmd/atn_cmds/tests.rs index cbbb23f6cc..bad5a85578 100644 --- a/crates/engine/src/cmd/atn_cmds/tests.rs +++ b/crates/engine/src/cmd/atn_cmds/tests.rs @@ -1087,7 +1087,7 @@ fn every_mapped_command_exports_and_imports_back() { ("layer.newFillLayer.pattern", json!({"pattern": "b7a3c1d2-0000-4000-8000-000000000001", "patternName": "Twin", "scale": 50})), ("image.mode.bitmap", json!({"method": "threshold"})), ("image.imageSize", json!({"resolution": 1200, "resample": "preserveDetails", "keepPrintSize": true, "scaleStyles": true})), - ("layer.new.layerFromBackground", json!({"ifPresent": true, "select": false})), + ("layer.new.layerFromBackground", json!({"ifPresent": true, "select": false, "show": false})), // COPYCAT, AJ_Actions2023 and the Line and Color tutorial set. ("layer.smartFilter.deleteFilterMask", json!({"ifPresent": true})), ("layer.smartFilter.blendingOptions", json!({"index": 1, "opacity": 0.5, "blend": "Darken"})), diff --git a/crates/engine/src/cmd/extra_cmds.rs b/crates/engine/src/cmd/extra_cmds.rs index fc19eb771c..56d557ccd0 100644 --- a/crates/engine/src/cmd/extra_cmds.rs +++ b/crates/engine/src/cmd/extra_cmds.rs @@ -492,12 +492,17 @@ fn layer_from_background(s: &mut Session, p: &Value) -> Result { // `select: false`: the targeted layer stays targeted, as when a Photoshop action's `set` // names the Background while another layer is selected. let select = p.get("select").and_then(Value::as_bool).unwrap_or(true); + // `show: false`: an action's `set` step on the Background replays the conversion and keeps + // its visibility, like the implicit conversions. + let show = p.get("show").and_then(Value::as_bool).unwrap_or(true); let id = s.edit("Layer From Background", |doc, active| { let l = doc.background_mut().ok_or(EngineError::Other("the document has no Background layer".into()))?; unlock_background(l); // Only this explicit conversion shows a hidden Background, as in the reference // application; implicit ones through `background_to_layer` keep its visibility. - l.visible = true; + if show { + l.visible = true; + } if select || active.is_none() { *active = Some(l.id); } @@ -1003,7 +1008,7 @@ pub fn specs() -> Vec { "Layer From Background…", &["Layer", "New"], None, - r##"{"ifPresent":bool=false (true: a document without a Background is left as it is, as a Photoshop action's step needs on an image that opened as a normal layer),"select":bool=true (false: the targeted layer stays targeted)}"##, + r##"{"ifPresent":bool=false (true: a document without a Background is left as it is, as a Photoshop action's step needs on an image that opened as a normal layer),"select":bool=true (false: the targeted layer stays targeted),"show":bool=true (true: a hidden Background becomes a visible layer, as the menu command does; false: it keeps its visibility, as an action's step does)}"##, has_background, layer_from_background ), diff --git a/crates/engine/src/cmd/layer_from_background_visible_tests.rs b/crates/engine/src/cmd/layer_from_background_visible_tests.rs index fa7053d600..4411c3c454 100644 --- a/crates/engine/src/cmd/layer_from_background_visible_tests.rs +++ b/crates/engine/src/cmd/layer_from_background_visible_tests.rs @@ -53,3 +53,13 @@ fn an_implicit_conversion_keeps_a_hidden_background_hidden() { assert_eq!(l.name, "Layer 0"); assert!(!l.visible); } + +#[test] +fn an_action_step_keeps_a_hidden_background_hidden() { + // An action's `set` step on the Background plays with `show: false`. + let mut s = session(true); + s.execute("layer.new.layerFromBackground", json!({"ifPresent": true, "select": false, "show": false})).unwrap(); + let l = background(&s); + assert_eq!(l.name, "Layer 0"); + assert!(!l.visible); +}