PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Refuse a Selective Color channel the command would refuse
Hamzaf30966569467
diff --git a/crates/engine/src/atn_cmds.rs b/crates/engine/src/atn_cmds.rsindex a4d6c33de..87749a64d 100644--- a/crates/engine/src/atn_cmds.rs+++ b/crates/engine/src/atn_cmds.rs@@ -740,8 +740,13 @@ fn selective_to(p: &Value) -> Option<Descriptor> {let row = rows.get_mut(i)?;let mut v = row.unwrap_or([0.0; 4]);for (slot, key) in v.iter_mut().zip(["cyan", "magenta", "yellow", "black"]) {- if let Some(n) = jnum(p, key) {- *slot = n;+ // A channel that is given but is not a number is an error in the command+ // (`adjust_cmds::selective_from_params`), so a step carrying one cannot be written+ // either: ignoring it would export a different adjustment than the one recorded.+ // `null` counts as absent there, and so here.+ match p.get(key) {+ None | Some(Value::Null) => {}+ Some(_) => *slot = jnum(p, key)?,}}*row = Some(v);diff --git a/crates/engine/src/atn_cmds/tests.rs b/crates/engine/src/atn_cmds/tests.rsindex 8ecf7334f..81766af2c 100644--- a/crates/engine/src/atn_cmds/tests.rs+++ b/crates/engine/src/atn_cmds/tests.rs@@ -197,6 +197,17 @@ fn a_selective_color_step_in_the_scalar_form_keeps_its_values() {// The array form is unchanged.let array = back(json!({"method": "relative", "yellows": [0, 0, -15, 5]}));assert_eq!(range(&array, "yellows"), [0.0, 0.0, -15.0, 5.0], "{array}");++ // A channel the command would refuse is not quietly dropped: the step is refused too, since+ // writing it would export an adjustment that is not the one recorded. `null` is absent, as+ // the command reads it.+ let mut s = Session::new();+ s.actions.list.push(Action::new("A", vec![("image.adjustments.selectiveColor".into(), json!({"colors": "reds", "cyan": "35"}))]));+ let e = s.execute("actions.save", json!({"action": "A"})).unwrap_err().to_string();+ assert!(e.contains("image.adjustments.selectiveColor"), "{e}");++ let nulled = back(json!({"colors": "reds", "cyan": 35, "magenta": null}));+ assert_eq!(range(&nulled, "reds"), [35.0, 0.0, 0.0, 0.0], "{nulled}");}#[test]