From f7942efd1d6869a9c788799108a2d348201bc61a Mon Sep 17 00:00:00 2001 From: abc2cb <271337822+abc2cb@users.noreply.github.com> Date: Sun, 18 Oct 2026 17:49:38 +0300 Subject: [PATCH] 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 --- crates/ui-egui/src/smart_ui.rs | 12 +++++++--- crates/ui-egui/src/smart_ui/editor_tests.rs | 26 +++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/smart_ui.rs b/crates/ui-egui/src/smart_ui.rs index 6ce5f9c7fe7..2cd61a3000d 100644 --- a/crates/ui-egui/src/smart_ui.rs +++ b/crates/ui-egui/src/smart_ui.rs @@ -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) { diff --git a/crates/ui-egui/src/smart_ui/editor_tests.rs b/crates/ui-egui/src/smart_ui/editor_tests.rs index c007b2ca6b6..c5814b8d172 100644 --- a/crates/ui-egui/src/smart_ui/editor_tests.rs +++ b/crates/ui-egui/src/smart_ui/editor_tests.rs @@ -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)); +}