From 51a5da427e01b4b8b2411c02fc91bf65fb1b4e9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcelo=20C=C3=A1rdenas?= Date: Thu, 8 Oct 2026 14:01:50 -0300 Subject: [PATCH] =?UTF-8?q?Filter=20=E2=80=BA=20Last=20Filter=20applies=20?= =?UTF-8?q?to=20the=20active=20layer,=20not=20the=20layer=20the=20filter?= =?UTF-8?q?=20first=20ran=20on=20(#1270)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Filter Gallery, Camera Raw and Adaptive Wide Angle dialogs record the layer they ran on in the command's params. Last Filter replayed the journal entry verbatim, so it filtered that layer again (possibly hidden, or deleted) and appeared to do nothing on the layer you were looking at. It now drops the recorded `layer`, so it applies to the current layer as in Photoshop. --- crates/engine/src/filters.rs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/filters.rs b/crates/engine/src/filters.rs index 2e59cb1b38f..f67ffad9e39 100644 --- a/crates/engine/src/filters.rs +++ b/crates/engine/src/filters.rs @@ -351,9 +351,15 @@ pub fn specs() -> Vec { ] } -/// The most recent filter command in the session journal. +/// The most recent filter command in the session journal, retargeted at the active layer: dialogs +/// such as the Filter Gallery record the layer they ran on, and Last Filter applies to the +/// current layer, as in Photoshop (#1270). fn last_filter(s: &Session) -> Option<(String, Value)> { - s.journal.iter().rev().find(|(id, _)| params_for(id, &Value::Null).is_some() && id.starts_with("filter.")).cloned() + let (id, mut params) = s.journal.iter().rev().find(|(id, _)| params_for(id, &Value::Null).is_some() && id.starts_with("filter.")).cloned()?; + if let Value::Object(m) = &mut params { + m.remove("layer"); + } + Some((id, params)) } #[cfg(test)] @@ -528,6 +534,24 @@ mod tests { assert_eq!(active_pixels(&s2), twice); } + #[test] + fn last_filter_applies_to_the_active_layer() { + let mut s = session(); + paint_pattern(&mut s); + let first = s.active().unwrap().active_layer.unwrap(); + // Dialogs (Filter Gallery, Camera Raw…) record the layer they ran on. + s.execute("filter.other.offset", json!({"horizontal": 3, "layer": first.0})).unwrap(); + let first_once = active_pixels(&s); + s.execute("layer.new.layer", json!({})).unwrap(); + paint_pattern(&mut s); + let before = active_pixels(&s); + s.execute("filter.lastFilter", json!({})).unwrap(); + assert_ne!(active_pixels(&s), before, "the active layer is filtered"); + let d = s.active().unwrap(); + let l = d.doc.layer(first).unwrap(); + assert_eq!(l.surface().unwrap().read_region(photocraft_geom::Rect::new(0, 0, 48, 32)), first_once, "the first layer is left alone"); + } + #[test] fn params_map_to_algorithm_units() { assert_eq!(params_for("filter.blur.gaussianBlur", &json!({"radius": 4.5})), Some(FilterParams::GaussianBlur { radius: 4.5 }));