SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Browser: Collapse All keeps the clicked row open (#8032) (#8033)
raykholod56dc310b09e
diff --git a/crates/engine/src/cmd/browser.rs b/crates/engine/src/cmd/browser.rsindex faaab35f05..1c72a5787c 100644--- a/crates/engine/src/cmd/browser.rs+++ b/crates/engine/src/cmd/browser.rs@@ -56,7 +56,7 @@ pub static COMMANDS: &[CommandSpec] = &[Display only: open/closed rows are not saved in the design and are not an undo step → open, open_by_default, closed_by_default",),CommandSpec::new("browser.collapse_all", "Collapse All", collapse_all).icon("folder").noundo().params(- "path?: [occurrence ids]; component?: id; omit both for the whole tree (the design row stays open so the first level remains visible). \+ "path?: [occurrence ids]; component?: id; omit both for the whole tree. The row it starts from (the design row for the whole tree) stays open, so its first level remains visible. \Display only; not an undo step → open, open_by_default, closed_by_default",),];@@ -562,8 +562,14 @@ fn fold_tree(s: &mut Session, p: &Value, open: bool, cmd: &str) -> Result<Value>FoldScope::Tree => walk_fold(s, &[], true, &mut keys, cmd)?,FoldScope::Occurrence(path) => walk_fold(s, path, false, &mut keys, cmd)?,}- if !open && matches!(scope, FoldScope::Tree) {- keys.open.remove("c0");+ if !open {+ // Collapse All folds what is under the clicked row; the row itself stays open.+ let own = match &scope {+ FoldScope::Tree => "c0".to_string(),+ FoldScope::Component(id) => format!("c{id}"),+ FoldScope::Occurrence(path) => occurrence_fold_key(path),+ };+ keys.open.remove(&own);}if keys.open.len().saturating_add(keys.closed.len()) > MAX_FOLD_KEYS {return Err(bad(cmd, "expand/collapse exceeds 10000 browser rows"));@@ -1993,7 +1999,7 @@ mod tests {let below = run(&mut s, "browser.collapse_all", json!({"path": [occ]}));let open = strs(&below, "open_by_default");- assert!(open.contains(&format!("o:{occ}")), "{open:?}");+ assert!(!open.contains(&format!("o:{occ}")), "the clicked row stays open: {open:?}");assert!(!open.contains(&"c0/bodies".into()), "{open:?}");assert!(strs(&below, "closed_by_default").iter().all(|k| !k.starts_with("c0") && k != "origin"), "{below}");diff --git a/crates/ui-egui/src/menu_tests.rs b/crates/ui-egui/src/menu_tests.rsindex 22e5b40925..491d97f64a 100644--- a/crates/ui-egui/src/menu_tests.rs+++ b/crates/ui-egui/src/menu_tests.rs@@ -624,12 +624,14 @@ fn expand_and_collapse_all_open_the_browser_tree_from_the_design_menu() {let created = app.run("component.create", json!({"name": "Part"})).unwrap();let occ = created["occurrence"].as_u64().unwrap();+ let child = app.run("component.create", json!({"name": "Inner", "parent_path": [occ]})).unwrap()["occurrence"].as_u64().unwrap();let path = vec![occ];act(&mut app, &Target::Occurrence { path: path.clone() }, "Collapse All");- assert!(app.tree.collapsed.contains(&format!("o:{occ}")), "{:?}", app.tree.collapsed);+ assert!(app.tree.collapsed.contains(&format!("o:{occ}/{child}")), "its children fold: {:?}", app.tree.collapsed);+ assert!(!app.tree.collapsed.contains(&format!("o:{occ}")), "the clicked row stays open: {:?}", app.tree.collapsed);assert!(!app.tree.collapsed.contains("c0/bodies"), "a placement's collapse leaves the rest of the tree: {:?}", app.tree.collapsed);act(&mut app, &Target::Occurrence { path }, "Expand All");- assert!(!app.tree.collapsed.contains(&format!("o:{occ}")), "{:?}", app.tree.collapsed);+ assert!(!app.tree.collapsed.contains(&format!("o:{occ}/{child}")), "{:?}", app.tree.collapsed);}#[test]