Browser: Collapse All keeps the clicked row open (#8032) (#8033)

Collapse All from a component or placement row folds everything under that
row and leaves the row itself open, matching the whole-tree Collapse All,
which already keeps the design row open.
This commit is contained in:
raykholo
2026-10-28 12:18:28 +00:00
committed by GitHub
parent 4ab612ea67
commit d56dc310b0
2 changed files with 14 additions and 6 deletions
+10 -4
View File
@@ -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}");
+4 -2
View File
@@ -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]