Move: scope box selection to the active component (#4459) (#4527)

* claim: #4459

* fix: scope Move box selection to active component (#4459)
This commit is contained in:
Colin Faulkingham
2026-10-23 20:25:00 +00:00
committed by GitHub
parent 6eaf723041
commit 71f7a8e697
2 changed files with 98 additions and 1 deletions
+92
View File
@@ -148,3 +148,95 @@ fn tab_in_the_box_goes_to_the_next_axis() {
let b = h.app.session.model.state().body("Body1").unwrap().mesh().bounds();
assert!((b.min.y - 12.0).abs() < 1e-6 && b.min.x.abs() < 1e-6, "moved along Y: {b:?}");
}
fn component_selection_fixture() -> crate::scenario::Harness {
let mut h = crate::scenario::Harness::new();
for (command, params) in [
("solid.box", json!({"length": 10, "width": 10, "height": 10, "corner": [-30, 0, 0], "body_name": "Outside"})),
("component.create", json!({"name": "Part"})),
("solid.box", json!({"length": 10, "width": 10, "height": 10, "body_name": "Inside"})),
("component.create", json!({"name": "Child"})),
("solid.box", json!({"length": 10, "width": 10, "height": 10, "corner": [30, 0, 0], "body_name": "Nested"})),
("component.activate", json!({"component": "root"})),
("component.create", json!({"name": "Sibling"})),
("solid.box", json!({"length": 10, "width": 10, "height": 10, "corner": [60, 0, 0], "body_name": "SiblingBody"})),
("component.activate", json!({"component": "Part"})),
] {
h.app.run(command, params).unwrap();
}
h.app.ui.show_browser = false;
h.app.ui.show_timeline = false;
h.app.ui.show_origin = false;
h.step(&json!({"call": "ui.view", "params": {"view": "top"}})).unwrap();
// Keep the selection rectangle to the right of the Move dialog.
h.step(&json!({"call": "ui.camera", "params": {"target": [0, 0, 0], "distance": 250}})).unwrap();
h
}
fn select_component_boxes(h: &mut crate::scenario::Harness, crossing: bool, add: bool) {
let ends = if crossing { [[75, -5, 0], [-35, 15, 0]] } else { [[-35, -5, 0], [75, 15, 0]] };
h.step(&json!({"drag": [{"world": ends[0]}, {"world": ends[1]}], "shift": add})).unwrap();
}
#[test]
fn move_box_selection_stays_in_the_active_component_and_its_children() {
for crossing in [false, true] {
let mut h = component_selection_fixture();
h.app.start("solid.move");
h.settle();
for add in [false, true] {
select_component_boxes(&mut h, crossing, add);
let names = h.app.dialog.as_ref().unwrap().inputs[0].items.body_names();
assert_eq!(names, ["Inside", "Nested"], "crossing={crossing}, add={add}");
}
}
}
#[test]
fn body_box_preselection_uses_component_scope_and_root_keeps_all_bodies() {
let mut h = component_selection_fixture();
select_component_boxes(&mut h, false, false);
assert_eq!(h.app.session.selection.body_names(), ["Inside", "Nested"]);
h.app.start("solid.move");
assert_eq!(h.app.dialog.as_ref().unwrap().inputs[0].items.body_names(), ["Inside", "Nested"]);
h.step(&json!({"key": "Escape"})).unwrap();
h.app.run("component.activate", json!({"component": "root"})).unwrap();
h.app.run("select.clear", json!({})).unwrap();
h.app.start("solid.move");
h.settle();
select_component_boxes(&mut h, true, false);
assert_eq!(h.app.dialog.as_ref().unwrap().inputs[0].items.body_names(), ["Outside", "Inside", "SiblingBody", "Nested"]);
}
#[test]
fn move_box_selection_uses_the_active_occurrence_path() {
let mut h = component_selection_fixture();
let part = h.app.session.active_component;
let second = h.app.run("occurrence.copy", json!({"component": part, "translate": [0, 30, 0]})).unwrap()["occurrence"].as_u64().unwrap();
h.app.run("component.activate", json!({"component": part, "occurrence": second, "path": [second]})).unwrap();
let mut expected = h.app.session.occurrence_bodies(&[second], true).unwrap();
expected.sort();
h.app.start("solid.move");
h.settle();
h.step(&json!({"drag": [{"world": [-35, -5, 0]}, {"world": [75, 45, 0]}]})).unwrap();
let mut names = h.app.dialog.as_ref().unwrap().inputs[0].items.body_names();
names.sort();
assert_eq!(names, expected, "only the active placement and its nested child are picked");
}
#[test]
fn move_reference_box_selection_can_still_use_an_inactive_body() {
let mut h = component_selection_fixture();
h.app.start("solid.move");
{
let d = h.app.dialog.as_mut().unwrap();
d.kind = kind(ROTATE);
d.inputs = inputs(ROTATE);
d.inputs[0].items = vec![Sel::Body { name: "Inside".into() }];
d.active = 1;
}
h.settle();
h.step(&json!({"drag": [{"world": [-35, -5, 0]}, {"world": [-15, 15, 0]}]})).unwrap();
let axis = &h.app.dialog.as_ref().unwrap().inputs[1].items;
assert!(matches!(axis.as_slice(), [Sel::Edge { body, .. }] if body == "Outside"), "{axis:?}");
}
+6 -1
View File
@@ -3802,8 +3802,13 @@ fn box_select(app: &mut SolveApp, proj: &Proj, bx: BoxSel, add: bool) {
}
} else {
let accept = app.dialog.as_ref().and_then(|d| d.active_input()).map(|i| i.accept).unwrap_or(BODIES);
// Bulk body selection follows the active component, just like its unfaded bodies.
// Keep other dialogs and Move's reference inputs free to pick across components.
let scoped_bodies = accept == BODIES && app.dialog.as_ref().is_none_or(|d| matches!(d.kind, crate::dialogs::Kind::Move { .. }));
let active_bodies =
app.session.active_occurrence_path.as_ref().filter(|_| scoped_bodies).and_then(|p| app.session.occurrence_bodies(p, true).ok());
for b in &st.bodies {
if !app.session.body_visible(&b.name) {
if !app.session.body_visible(&b.name) || (scoped_bodies && body_faded(app, b, &active_bodies)) {
continue;
}
let m = b.mesh();