Actions: a Gradient Fill Make exports with stops, keeps extra layer props (#11249)

Two CodeRabbit findings on #11249:
- A layer.newFillLayer.gradient step with from, to and stops plays the
  stops, but the ATN export refused it. from/to are now left out beside
  stops.
- A recorded Make whose Usng also held a name, opacity, mode or clipping
  loaded as the plain command, which plays none of them and saved back
  without them. It now stays the recorded step.

Each has a test that fails without the fix.

Co-Authored-By: NaufalDzz <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
committed 2026-11-06 15:58:57 +01:00
1 parent 92de311b2b
commit 9d6cdca3fc
2 files changed
+19 -3

No files matched your search

+6 -3
View File
@@ -276,9 +276,11 @@ fn gradient_make_to(p: &Value) -> Option<Descriptor> {
if o.remove("path").is_some_and(|v| !v.is_null()) {
return None;
}
// Stops replace `from` and `to` when the step plays, so those two are left out beside them.
match (o.remove("from").filter(|v| !v.is_null()), o.remove("to").filter(|v| !v.is_null())) {
_ if o.contains_key("stops") => {}
(None, None) => {}
(Some(a), Some(b)) if !o.contains_key("stops") => {
(Some(a), Some(b)) => {
o.insert("stops".into(), json!([[0, a], [1, b]]));
}
_ => return None,
@@ -649,9 +651,10 @@ pub(super) fn make_from(d: &Descriptor) -> Mapped {
Some(p) => step("layer.newFillLayer.pattern", Value::Object(p)),
None => Mapped::Unsupported { harmless: false },
},
// A name, opacity, mode or clipping beside `Type` would neither play nor save back.
Some(t) if t.class_id.is("gradientLayer") => match gradient_step(t) {
Some(p) => step("layer.newFillLayer.gradient", p),
None => Mapped::Unsupported { harmless: false },
Some(p) if using.is_some_and(|u| u.items.iter().all(|(k, _)| k.is("Type"))) => step("layer.newFillLayer.gradient", p),
_ => Mapped::Unsupported { harmless: false },
},
_ => Mapped::Unsupported { harmless: false },
},
+13
View File
@@ -6446,6 +6446,11 @@ fn gradient_fill_steps_export_and_import_back() {
let mut expected = json!({"angle": 45, "stops": [[0, "#ff0000"], [1, "#0000ff"]], "transparency": [[0, 100], [1, 100]], "midpoints": []});
normalise(&mut expected);
assert_eq!((steps[0].0.as_str(), without_hidden(&steps[0].1)), ("layer.newFillLayer.gradient", expected));
// Stops replace `from` and `to` when it plays, so a Make with all three exports its stops.
let p = json!({"from": "#ff0000", "to": "#0000ff", "stops": [[0, "#00ff00"], [1, "#ffffff"]], "transparency": [[0, 100], [1, 100]]});
let item = export_item("layer.newFillLayer.gradient", &p, "S").unwrap();
let Mapped::Steps(steps) = (event_for(&item.event).unwrap().from)(item.descriptor.as_ref().unwrap()) else { panic!("did not import") };
assert_eq!(steps[0].1["stops"], json!([[0.0, "#00ff00"], [1.0, "#ffffff"]]));
// What the event cannot hold is refused: a Set without its transparency, toolbox colours,
// dragged handles, a path, a midpoint off a whole percent.
for (id, p) in [
@@ -6498,6 +6503,14 @@ fn gradient_fills_the_command_cannot_play_stay_photoshop_steps() {
let imp = import(&atn::write(&one_action(vec![gradient_set(t)])).unwrap()).unwrap();
assert_eq!(imp.actions[0].steps[0].0, PHOTOSHOP_STEP);
}
// A Make whose new layer also gets a name, opacity, mode or clipping: the command plays none
// of them, so the step stays as recorded.
for (key, v) in [("Nm ", text("Sky")), ("Opct", pct(50.0)), ("Md ", enm("BlnM", "Mltp")), ("Grup", D::Boolean(true))] {
let using = desc("contentLayer").with("Type", D::Descriptor(base.clone())).with(key, v);
let make = item("Mk ", "Make", Some(desc("null").with("null", class_ref("contentLayer")).with("Usng", D::Descriptor(using))));
let imp = import(&atn::write(&one_action(vec![make])).unwrap()).unwrap();
assert_eq!(imp.actions[0].steps[0].0, PHOTOSHOP_STEP, "{key}");
}
}
fn blend_if_entry(channel: &str, this: [i32; 4], under: Option<[i32; 4]>) -> D {