Smart Filter editor starts missing parameters from the spec defaults

open_editor opened the filter's dialog and copied the recorded parameters over
its fields. filter_dialog::open starts from the user's last-used values, so a
recorded filter that lacked a key (an older file, or a command that gained a
parameter) showed, and on OK saved, the remembered value instead of the
default. Reset the freshly opened filter dialog to the schema defaults, as
Alt+Cancel does, before the recorded parameters are copied in. Adjustment
editors are unchanged, and a plain Filter menu dialog still remembers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
abc2cbandClaude Opus 5.5 committed 2026-10-18 17:49:38 +03:00
1 parent 710c26af41
commit f7942efd1d
2 files changed
+35 -3

No files matched your search

+9 -3
View File
@@ -356,9 +356,15 @@ pub fn open_editor(app: &mut PhotocraftApp, ctx: &egui::Context, layer: u64, sm:
return;
}
};
let Some(id) = crate::adjust_dialog::open(app, &f.command)
.or_else(|| crate::filter_dialog::has_dialog(&f.command).then(|| crate::filter_dialog::open(app, &f.command)).flatten())
else {
let Some(id) = crate::adjust_dialog::open(app, &f.command).or_else(|| {
let id = crate::filter_dialog::has_dialog(&f.command).then(|| crate::filter_dialog::open(app, &f.command)).flatten()?;
// The filter dialog opens on the user's last-used values; a recorded filter that lacks a
// key must show (and save) the schema default instead.
let mut fields = app.ui.dialog_mut(id)?.fields.clone();
crate::filter_dialog::reset_fields(app, &mut fields);
app.ui.dialog_mut(id)?.fields = fields;
Some(id)
}) else {
return;
};
if let Some(d) = app.ui.dialog_mut(id) {
@@ -152,3 +152,29 @@ fn ctrl_i_uses_existing_invert_command_and_undo_redo_keep_the_source() {
h.state_mut().run("edit.redo", json!({})).unwrap();
assert_eq!(smart(h.state(), layer).smart_filters.len(), 3);
}
/// A recorded filter that lacks a parameter reopens with the schema default for it, not with the
/// value the user last used in that filter's dialog; the parameters it does hold still win.
#[test]
fn filter_editor_starts_missing_parameters_from_defaults_not_remembered_values() {
let (mut app, layer) = app(8, "rgb");
let command = "filter.sharpen.smartSharpen";
app.session.prefs.edit(|p| {
p.dialogs.insert(command.into(), json!({"reduceNoise": 60, "radius": 9}));
});
let ctx = egui::Context::default();
let mut sm = smart(&app, layer).clone();
let index = sm.smart_filters.iter().position(|f| f.command == command).unwrap();
sm.smart_filters[index].params = json!({"amount": 125, "radius": 2});
super::open_editor(&mut app, &ctx, layer.0, &sm, index);
let fields = &app.ui.dialogs.last().unwrap().fields;
assert!(fields.contains_key("__smartFilter"), "it edits the recorded filter");
assert_eq!(fields["reduceNoise"].as_f64(), Some(10.0), "the spec default, not the remembered 60");
assert_eq!(fields["amount"].as_f64(), Some(125.0));
assert_eq!(fields["radius"].as_f64(), Some(2.0), "recorded values beat the remembered 9");
// A plain Filter menu dialog still starts from the remembered values.
let id = crate::filter_dialog::open(&mut app, command).unwrap();
assert_eq!(app.ui.dialog_mut(id).unwrap().fields["reduceNoise"].as_f64(), Some(60.0));
}