Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Merge PR #7968: fix(atn): a Group Layers step keeps its explicit layer through .atn (#7236)

aiongg4eef797fdfd3
diff --cc crates/engine/src/atn_cmds/tests.rs
index 7ff734b61,da73404ad..2e89dab8e
--- a/crates/engine/src/atn_cmds/tests.rs
+++ b/crates/engine/src/atn_cmds/tests.rs
@@@ -591,45 -518,54 +591,93 @@@ fn bucket_keeps_an_explicit_color_throu
}
}
+/// `image.adjustments.photoFilter` exported to .atn and imported back → its params, or None.
+fn photo_filter_round_trip(params: Value) -> Option<Value> {
+ let item = export_item("image.adjustments.photoFilter", &params, "S")?;
+ let e = event_for(&item.event)?;
+ match (e.from)(item.descriptor.as_ref()?) {
+ Mapped::Steps(steps) => steps.first().map(|(id, p)| {
+ assert_eq!(id, "image.adjustments.photoFilter");
+ p.clone()
+ }),
+ _ => None,
+ }
+}
+
+ /// A `Mk` layerSection step exported to .atn and imported back → (id, params), or None.
+ fn group_round_trip(id: &str, params: &Value) -> Option<(String, Value)> {
+ let item = export_item(id, params, "S")?;
+ let e = event_for(&item.event)?;
+ match (e.from)(item.descriptor.as_ref()?) {
+ Mapped::Steps(steps) => steps.first().map(|(i, p)| (i.clone(), p.clone())),
+ _ => None,
+ }
+ }
+
+#[test]
+fn photo_filter_preset_only_step_keeps_its_resolved_color() {
+ // #7235: the Photoshop descriptor keeps only a colour (`phfl`/`PhtF` are colour-only; the io
+ // notes reach the same conclusion from the CS2 oracles). A step recorded with only `filter`
+ // previously exported with no colour at all, so re-imported playback fell back to the default
+ // warming filter; it must export the resolved colour of the chosen preset instead.
+ let mut back = photo_filter_round_trip(json!({"filter": "cooling80", "density": 60, "preserveLuminosity": true})).unwrap();
+ normalise(&mut back);
+ assert_eq!(back, json!({"color": "#006dff", "density": 60, "preserveLuminosity": true}));
+ // An omitted density stays omitted: running the imported step applies the same default.
+ let mut back = photo_filter_round_trip(json!({"filter": "red"})).unwrap();
+ normalise(&mut back);
+ assert_eq!(back, json!({"color": "#ea1a1a"}));
+ // With an explicit colour too, the colour wins, as when running the command.
+ let mut back = photo_filter_round_trip(json!({"filter": "cooling80", "color": "#123456", "density": 25})).unwrap();
+ normalise(&mut back);
+ assert_eq!(back, json!({"color": "#123456", "density": 25}));
+ let mut back = photo_filter_round_trip(json!({"color": "#123456", "density": 25})).unwrap();
+ normalise(&mut back);
+ assert_eq!(back, json!({"color": "#123456", "density": 25}));
+ // An unknown preset id keeps the old export: no colour resolves, playback applies its default.
+ let mut back = photo_filter_round_trip(json!({"filter": "nope", "density": 25})).unwrap();
+ normalise(&mut back);
+ assert_eq!(back, json!({"density": 25}));
+}
+
+ #[test]
+ fn group_layers_keeps_its_explicit_target_through_atn() {
+ // #7236: a recorded step with an explicit layer groups that layer, not the current
+ // selection. The source goes into the `From` reference by name and comes back the same
+ // way; a step with no source layer keeps the implicit form, imported as before.
+ let (id, p) = group_round_trip("layer.groupLayers", &json!({"layer": "A", "name": "Group"})).unwrap();
+ assert_eq!(id, "layer.groupLayers");
+ assert_eq!(p, json!({"layer": "A", "name": "Group"}));
+ // The implicit form survives unchanged: the reference stays the target layer.
+ let (id, p) = group_round_trip("layer.groupLayers", &json!({"name": "Group"})).unwrap();
+ assert_eq!(id, "layer.groupLayers");
+ assert_eq!(p, json!({"name": "Group"}));
+ let (id, p) = group_round_trip("layer.groupLayers", &json!({})).unwrap();
+ assert_eq!(id, "layer.groupLayers");
+ assert_eq!(p, json!({}));
+ // Group Without Layers: no `From` at all, imported as a plain new group.
+ let (id, p) = group_round_trip("layer.new.group", &json!({"name": "G"})).unwrap();
+ assert_eq!(id, "layer.new.group");
+ assert_eq!(p, json!({"name": "G"}));
+ }
+
+ #[test]
+ fn group_layers_from_index_reference_stays_implicit() {
+ // A Photoshop-authored `From` that names nothing portable (a zero-based index) keeps the
+ // old implicit import instead of inventing a wrong explicit target (#7236, edge).
+ let d = desc("null")
+ .with("null", class_ref("layerSection"))
+ .with("From", D::Reference(vec![ReferenceItem::Index { class: class("Lyr "), index: 2 }]))
+ .with("Usng", D::Descriptor(desc("layerSection").with("Nm ", text("Group"))));
+ match make_from(&d) {
+ Mapped::Steps(steps) => {
+ assert_eq!(steps[0].0, "layer.groupLayers");
+ assert_eq!(steps[0].1, json!({"name": "Group"}));
+ }
+ _ => panic!("an index source imports as the implicit form"),
+ }
+ }
+
#[test]
fn unsupported_shapes_become_photoshop_steps_not_errors() {
// Image size in two different percentages, a Paint Bucket click in percent of the canvas, a