Smart filters: the dialog's preview window shows the edited filter too (#6324)

The filter dialog's own preview window matched the canvas preview by the
filter's command, but an edited smart filter previews as
layer.smartFilter.setParams, so the window kept the unfiltered image.
smart_ui::preview_command names the command the preview runs.
This commit is contained in:
itsF4LCON committed 2026-10-16 00:15:50 +02:00
1 parent 0504331c51
commit 8176b613ca
2 files changed
+13 -1

No files matched your search

+3 -1
View File
@@ -43,7 +43,9 @@ pub(crate) fn window(app: &PhotocraftApp, dialog: u64, ui: &mut egui::Ui, f: &mu
// decides whether the filtered result (rather than the original) is shown.
let preview_on = f.get("__preview").and_then(Value::as_bool) == Some(true);
let filtered: Option<(FilterPreviewKey, std::sync::Arc<Document>)> = app.filter_preview.as_ref().and_then(|p| {
(preview_on && p.key.dialog == dialog && p.key.doc == doc_id && p.key.command == cmd).then(|| p.result.clone().map(|r| (p.key.clone(), r))).flatten()
// An edited smart filter previews as `layer.smartFilter.setParams` (#6324).
let previewed = crate::smart_ui::preview_command(f, &cmd);
(preview_on && p.key.dialog == dialog && p.key.doc == doc_id && p.key.command == previewed).then(|| p.result.clone().map(|r| (p.key.clone(), r))).flatten()
});
// The proxy factor the preview runs at (the filtered key's when it exists, else the request's).
let base_k = filtered.as_ref().map(|(k, _)| k.k).unwrap_or_else(|| {
+10
View File
@@ -331,6 +331,12 @@ fn edit_filter(app: &mut PhotocraftApp, id: u64, layer: u64, index: usize, param
}
}
/// The command a filter dialog's live preview runs ([`confirm_command`]'s): `layer.smartFilter.setParams`
/// while it edits a smart filter (#6324), else `command`.
pub fn preview_command<'a>(fields: &serde_json::Map<String, Value>, command: &'a str) -> &'a str {
if fields.contains_key("__smartFilter") { "layer.smartFilter.setParams" } else { command }
}
/// The command a confirmed filter dialog runs: smart-filter edits update the recorded filter.
pub fn confirm_command(fields: &serde_json::Map<String, Value>, command: String, params: Value) -> (String, Value) {
match fields.get("__smartFilter") {
@@ -485,6 +491,10 @@ mod tests {
crate::canvas::ensure_filter_preview(&mut app, 0, &egui::Context::default()).expect("a preview");
let preview = app.filter_preview.as_ref().unwrap();
assert_eq!(preview.key.command, "layer.smartFilter.setParams");
// The dialog's own preview window matches it to the dialog by that command.
let fields = &app.ui.dialogs.last().unwrap().fields;
assert_eq!(preview_command(fields, "filter.blur.gaussianBlur"), preview.key.command);
assert_eq!(preview_command(&serde_json::Map::new(), "filter.blur.gaussianBlur"), "filter.blur.gaussianBlur");
let shown = preview.result.clone().expect("the preview's document");
let filters = smart(&app, &shown).smart_filters;
assert_eq!(filters.len(), 1, "the edited filter is replaced, not stacked");