mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-11 20:52:55 +00:00
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
1a9be65e0f
commit
533cf55ef5
2 files changed
+23
-2
No files matched your search
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in new issue
Block a user