From 533cf55ef5edccbc9de0711d07951a2f0fb65cdc Mon Sep 17 00:00:00 2001 From: David Mann Date: Wed, 4 Nov 2026 17:32:59 +0100 Subject: [PATCH] Fix-up #11235 (review): a filter already on at the row's first draw deselects With no criteria kept yet (the row's first draw, e.g. after ui.set while the panel was closed), a filter that is on counts as applied. Co-Authored-By: Claude Opus 5.5 --- .../src/panels/layer_filter_ui/selection.rs | 5 +++-- .../panels/layer_filter_ui/selection_tests.rs | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/panels/layer_filter_ui/selection.rs b/crates/ui-egui/src/panels/layer_filter_ui/selection.rs index 344d60b061..50eb4f29f1 100644 --- a/crates/ui-egui/src/panels/layer_filter_ui/selection.rs +++ b/crates/ui-egui/src/panels/layer_filter_ui/selection.rs @@ -12,7 +12,8 @@ use crate::PhotocraftApp; /// Deselect the layers the filter hides when its criteria changed since the last call. The /// criteria are kept in `ctx`'s memory, so a change from the filter row or from `ui.set -/// {layerFilter}` is seen the next time the row is drawn. +/// {layerFilter}` is seen the next time the row is drawn; with nothing kept yet (the row's first +/// draw, e.g. after `ui.set` while the panel was closed) a filter that is on counts as applied. pub fn follow(app: &mut PhotocraftApp, ctx: &egui::Context) { let id = egui::Id::unique("layer-filter-applied"); let now = Filter::of(&app.ui); @@ -21,7 +22,7 @@ pub fn follow(app: &mut PhotocraftApp, ctx: &egui::Context) { d.insert_temp(id, now.clone()); before }); - if before.is_some_and(|b| b != now) && now.active() { + if before.is_none_or(|b| b != now) && now.active() { deselect_hidden(app); } } diff --git a/crates/ui-egui/src/panels/layer_filter_ui/selection_tests.rs b/crates/ui-egui/src/panels/layer_filter_ui/selection_tests.rs index 291e4ba6d0..a468741190 100644 --- a/crates/ui-egui/src/panels/layer_filter_ui/selection_tests.rs +++ b/crates/ui-egui/src/panels/layer_filter_ui/selection_tests.rs @@ -69,6 +69,26 @@ fn a_filter_that_hides_the_selected_layer_deselects_it_and_turning_it_off_keeps_ assert_eq!(selection(&h), none(), "turning the filter off does not bring the selection back"); } +/// Batch 16 review: a filter already on when the row is first drawn (set before the panel drew, +/// as `ui.set {layerFilter}` can) deselects the layers it hides too. +#[test] +fn a_filter_on_before_the_rows_first_draw_deselects_the_hidden_layers() { + let mut s = photocraft_engine::Session::new(); + s.execute("file.new", json!({"width": 64, "height": 48})).unwrap(); + s.execute("layer.new.layer", json!({"name": "Red"})).unwrap(); + s.execute("type.create", json!({"text": "Hello", "x": 4, "y": 20, "size": 12})).unwrap(); + let red = s.active().unwrap().doc.walk().into_iter().find(|(_, _, l)| l.name == "Red").map(|(_, _, l)| l.id).unwrap(); + s.execute("layer.select", json!({"layer": red.0})).unwrap(); + let mut h = Harness::builder().with_size(vec2(1440.0, 900.0)).with_max_steps(64).build_eframe(move |cc| { + PhotocraftApp::setup_context(&cc.egui_ctx, Default::default()); + let mut app = PhotocraftApp::new(s, crate::Services::default()); + app.ui.layer_filter = vec!["type".into()]; + app + }); + h.run_steps(8); + assert_eq!(selection(&h), none(), "Kind › Type hides Red from the first draw on"); +} + #[test] fn a_filter_that_lists_none_of_the_selected_layers_deselects_them_all() { let mut h = harness();