Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

fix(ui): allow collapsing brush folders while searching (storytold/photocraft#7257)

nrq6993-a11y33398aeb1cad
diff --git a/crates/ui-egui/src/brush_panel_tests.rs b/crates/ui-egui/src/brush_panel_tests.rs
index 670f442be..9152c260c 100644
--- a/crates/ui-egui/src/brush_panel_tests.rs
+++ b/crates/ui-egui/src/brush_panel_tests.rs
@@ -825,11 +825,32 @@ fn brushes_panel_groups_collapse_and_filter() {
let n = brush_preview::render_count(&ctx);
assert_eq!(shown(&mut h), all);
assert_eq!(brush_preview::render_count(&ctx), n);
- // A filter shows matching presets even in collapsed groups.
+ // Search still respects collapsed groups (#7257).
let first = h.state().session.tools.presets[0].name.clone();
h.state_mut().ui.brushes_panel.filter = first.to_uppercase();
h.run_steps(2);
- assert!(brush_preview::render_count(&ctx) >= n);
+ assert_eq!(shown(&mut h), all);
+ assert_eq!(brush_preview::render_count(&ctx), n);
+}
+
+/// #7257: with a search filter active, nested folders that contain matches can still be closed.
+#[test]
+fn brush_search_allows_collapsing_nested_folders() {
+ use egui_kittest::kittest::Queryable;
+ let mut h = harness(1, 0);
+ let builtin_groups: Vec<String> = grouped_presets(&h.state().session.tools.presets).into_iter().map(|(g, _)| g).collect();
+ h.state_mut().ui.brushes_panel.collapsed = builtin_groups;
+ for p in [kit("Kit Top", &[]), kit("Kit Pen", &["Test Inks"]), kit("Kit Nib", &["Test Inks", "Test Fine"])] {
+ h.state_mut().session.tools.presets.push(p);
+ }
+ h.state_mut().ui.brushes_panel.filter = "Kit".into();
+ h.run_steps(3);
+ assert!(h.query_by_label("Kit Nib").is_some(), "search shows nested matches");
+ h.get_by_label("Test Inks").click();
+ h.run_steps(3);
+ assert_eq!(h.state().ui.brushes_panel.collapsed.last().map(String::as_str), Some("Kit/Test Inks"));
+ assert!(h.query_by_label("Kit Nib").is_none() && h.query_by_label("Test Fine").is_none());
+ assert!(h.query_by_label("Kit Pen").is_none());
}
fn kit(name: &str, folder: &[&str]) -> paint::BrushPreset {
diff --git a/crates/ui-egui/src/brushes_tab.rs b/crates/ui-egui/src/brushes_tab.rs
index 3f45526e5..b2fefa25a 100644
--- a/crates/ui-egui/src/brushes_tab.rs
+++ b/crates/ui-egui/src/brushes_tab.rs
@@ -732,7 +732,6 @@ struct Draw<'a> {
/// The selected preset's name (by identity, so look-alike duplicates stay distinct).
current: Option<&'a str>,
collapsed: &'a [String],
- filtering: bool,
grid: bool,
layout: ListLayout,
/// The picker cards' parts — name, stroke, tip — from the gear's boxes.
@@ -824,7 +823,7 @@ fn draw_nodes(ui: &mut egui::Ui, d: &Draw, nodes: &[Node], depth: usize, acts: &
Node::Preset(p) => run.push(p),
Node::Folder(f) => {
flush(ui, &mut run, acts);
- let open = d.filtering || !d.collapsed.contains(&folder_view_key(d.label, &f.path));
+ let open = !d.collapsed.contains(&folder_view_key(d.label, &f.path));
group_header(ui, d.label, d.key, &f.path, open, f.count, acts);
if open && depth < MAX_VIEW_DEPTH {
draw_nodes(ui, d, &f.children, depth + 1, acts);
@@ -902,12 +901,12 @@ pub fn preset_list(ui: &mut egui::Ui, presets: &[BrushPreset], current: Option<&
continue;
}
let key = group_key(presets, &label);
- let open = !filter.is_empty() || !collapsed.contains(&label);
+ let open = !collapsed.contains(&label);
group_header(ui, &label, &key, &[], open, items.len(), &mut acts);
if !open {
continue;
}
- let d = Draw { label: &label, key: &key, presets, current, collapsed, filtering: !filter.is_empty(), grid, layout, show, scale: st.scale };
+ let d = Draw { label: &label, key: &key, presets, current, collapsed, grid, layout, show, scale: st.scale };
draw_nodes(ui, &d, &folder_tree(&items), 0, &mut acts);
ui.add_space(2.0);
}