Replace params for every adjustment smart filter dialog and Shape Blur

Color Lookup uses the schema dialog, which removes an emptied text key, so
a stale data or file was read over the chosen lut. Key the replacement on
image.adjustments.* rather than the dedicated editors. setParams' replace
now also holds for Shape Blur, which merged before resolving its shape.
This commit is contained in:
Khawar Zamman Wani committed 2026-11-06 12:01:12 +05:30
1 parent 2e13ec280b
commit 390b3b388a
4 files changed
+54 -4

No files matched your search

+3 -1
View File
@@ -185,7 +185,9 @@ pub(super) fn set_filter_params(s: &mut Session, p: &Value) -> Result<Value> {
let doc = &s.active().ok_or(EngineError::NoDocument)?.doc;
let sm = smart(doc, layer_param(s, p)?)?;
let f = sm.smart_filters.get(filter_index(CMD, p, sm)?).ok_or_else(|| bad(CMD, "no smart filter at this index"))?;
let shape_params = if f.command == "filter.blur.shapeBlur" { Some(edited_shape_params(s, &f.params, &new)?) } else { None };
let nothing = json!({});
let previous = if replace { &nothing } else { &f.params };
let shape_params = if f.command == "filter.blur.shapeBlur" { Some(edited_shape_params(s, previous, &new)?) } else { None };
(f.command == DISPLACE, shape_params)
};
let new_map = if displace && new_map_asked {
+16
View File
@@ -1418,3 +1418,19 @@ fn set_params_replace_drops_the_keys_it_leaves_out() {
s.undo();
assert_eq!(params(&s), json!({"monochrome": false, "gray": [30, 30, 40, 0]}));
}
/// `replace` also holds for Shape Blur, whose settings otherwise merge before its shape resolves.
#[test]
fn set_params_replace_drops_a_shape_blur_radius_it_leaves_out() {
let mut s = session(8);
paint(&mut s);
convert(&mut s);
s.execute("filter.blur.shapeBlur", json!({"radius": 5, "shape": "circle"})).unwrap();
let params = |s: &Session| active_smart(s).smart_filters[0].params.clone();
s.execute("layer.smartFilter.setParams", json!({"params": {"shape": "circle"}})).unwrap();
assert_eq!(params(&s)["radius"], json!(5), "merged by default");
s.execute("layer.smartFilter.setParams", json!({"params": {"shape": "circle"}, "replace": true})).unwrap();
assert!(params(&s).get("radius").is_none(), "replaced: {}", params(&s));
}
@@ -134,10 +134,10 @@ pub(crate) fn edit_command(app: &PhotocraftApp, fields: &Map<String, Value>) ->
}
Ok((COMMAND.into(), params))
} else {
// An adjustment's editor opens on all the recorded settings and may remove keys, so OK
// An adjustment's dialog opens on all the recorded settings and may remove keys, so OK
// replaces them: merged, a removed one stays stored and can override the edit (a stale
// Channel Mixer `gray` is read over `red`).
let replace = fields.contains_key("__adjust");
// Channel Mixer `gray` is read over `red`, a stale Color Lookup `data` over `lut`).
let replace = fields.get("__command").and_then(Value::as_str).is_some_and(|c| c.starts_with("image.adjustments."));
Ok((
"layer.smartFilter.setParams".into(),
json!({"layer": layer.0, "index": index, "params": crate::filter_dialog::params_of(fields), "replace": replace}),
@@ -199,6 +199,7 @@ fn adjustment_filter(mode: &str, command: &str, params: serde_json::Value) -> (P
(app, id)
}
/// The smart object on layer `id`.
fn recorded(app: &PhotocraftApp, id: u64) -> photocraft_doc::SmartObject {
match &app.session.active().unwrap().doc.layer(photocraft_doc::LayerId(id)).unwrap().content {
photocraft_doc::LayerContent::Smart(sm) => sm.clone(),
@@ -263,4 +264,35 @@ fn a_lab_curves_smart_filter_keeps_a_lightness_edit() {
let photocraft_doc::Adjustment::Curves { per_channel, .. } = read(&sm.smart_filters[0].params) else { panic!("Curves params") };
let photocraft_doc::Adjustment::Curves { per_channel: wanted, .. } = read(&json!({"lightness": edited})) else { panic!("Curves params") };
assert_eq!(per_channel[0], wanted[0], "the edited Lightness renders");
assert!(sm.smart_filters[0].params.get("points").is_none(), "the removed alias is not stored");
}
/// Emptying a text field removes its key from the Color Lookup dialog, which draws from the
/// command's schema. A stored `data` would be read over the `lut` chosen instead.
#[test]
fn a_color_lookup_smart_filter_with_its_data_cleared_uses_the_chosen_lut() {
let mut cube = String::from("LUT_3D_SIZE 2\n");
for b in 0..2 {
for g in 0..2 {
for r in 0..2 {
cube.push_str(&format!("{} {} {}\n", 1 - r, 1 - g, 1 - b));
}
}
}
let (app, id) = adjustment_filter("rgb", "image.adjustments.colorLookup", json!({"data": cube, "fileName": "invert.cube"}));
let (mut h, dialog) = edit_first_filter(app, id);
let fields = &mut h.state_mut().ui.dialog_mut(dialog).unwrap().fields;
assert_eq!(fields.get("data"), Some(&json!(cube)), "opens on the recorded settings");
fields.insert("data".into(), json!(""));
fields.insert("lut".into(), json!("warm"));
h.run_steps(2);
let fields = &h.state_mut().ui.dialog_mut(dialog).unwrap().fields;
assert!(!fields.contains_key("data"), "the dialog removed the emptied field");
crate::dialogs::confirm(h.state_mut(), dialog).unwrap();
let sm = recorded(h.state(), id);
assert_eq!(sm.smart_filters.len(), 1, "no filter was stacked");
let params = &sm.smart_filters[0].params;
assert!(params.get("data").is_none(), "the removed data is not stored: {params}");
assert_eq!(params.get("lut"), Some(&json!("warm")));
}