From 1a953736ff4a79fd6d8b082c281702044b87b8f2 Mon Sep 17 00:00:00 2001 From: DuBearte <130190089+DuBearte@users.noreply.github.com> Date: Fri, 23 Oct 2026 13:44:32 +0000 Subject: [PATCH] Combine takes bodies clicked in the Browser (#4452) (#4766) * claim: #4452 Co-Authored-By: Claude Opus 5.5 * Combine takes bodies clicked in the Browser (#4452) A body row in the Browser only replaced the selection, so with Combine open its target and tools stayed empty and overlapping bodies could only be picked in the view. When the open dialog's active input takes bodies, a body row now goes there, as plane and axis rows already do. Co-Authored-By: Claude Opus 5.5 * Combine Browser picks: test both layouts and control-channel clicks (#4452) Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- crates/ui-egui/src/browser.rs | 17 ++++++++++++ crates/ui-egui/src/preselect_tests.rs | 40 +++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/crates/ui-egui/src/browser.rs b/crates/ui-egui/src/browser.rs index caf16527f..880786578 100644 --- a/crates/ui-egui/src/browser.rs +++ b/crates/ui-egui/src/browser.rs @@ -1580,9 +1580,24 @@ impl CanvasPanel { } } +/// Does the open dialog's active input take bodies (Combine's target and tools, #4452)? Then a +/// body clicked in the Browser goes there, as a click on it in the view does, rather than +/// replacing the selection: overlapping bodies are often only told apart in the Browser. +fn dialog_takes_body(app: &SolveApp) -> bool { + app.dialog.as_ref().and_then(|d| d.active_input()).is_some_and(|i| i.accept & crate::selection::BODIES != 0) +} + /// A browser click on a plane or axis: it goes to the open dialog's input if that takes it, /// otherwise it becomes the selection. fn pick_from_browser(app: &mut SolveApp, x: Sel) { + if let Sel::Body { .. } = &x + && dialog_takes_body(app) + && let Some(mut d) = app.dialog.take() + { + d.pick(&app.session, x); + app.dialog = Some(d); + return; + } let hit = match &x { Sel::Plane { name } => crate::viewport::Hit::Plane { name: name.clone(), point: solidcraft_engine::geom::Vec3::ZERO }, Sel::Axis { name } => crate::viewport::Hit::Axis { name: name.clone() }, @@ -1978,6 +1993,8 @@ fn entry_row( if let Some(s) = e.sel.clone() { pick_from_browser(app, s); } + } else if let Some(s) = e.sel.clone().filter(|s| matches!(s, Sel::Body { .. }) && dialog_takes_body(app)) { + pick_from_browser(app, s); } else { click_select(app, ui, e.row_key.clone(), e.sel.clone()); } diff --git a/crates/ui-egui/src/preselect_tests.rs b/crates/ui-egui/src/preselect_tests.rs index 0a8893773..c3d040ab1 100644 --- a/crates/ui-egui/src/preselect_tests.rs +++ b/crates/ui-egui/src/preselect_tests.rs @@ -2272,3 +2272,43 @@ fn hovering_a_large_body_does_not_wait_for_its_pick_index() { assert!(matches!(h.app.viewport.hover, Some(crate::viewport::Hit::Face { .. })), "{:?}", h.app.viewport.hover); assert!(hover_ms < index_ms / 3.0, "the first hover took {hover_ms:.1} ms; making the index takes {index_ms:.1} ms"); } + +/// #4452: with Combine open, bodies clicked in the Browser fill its inputs, as clicks on them +/// in the view do: the first is the target, the next the tools. Overlapping bodies are often +/// only told apart in the Browser. +#[test] +fn combine_takes_bodies_clicked_in_the_browser() { + for layout in ["docked", "floating"] { + for control in [false, true] { + combine_takes_bodies_clicked_in_the_browser_in(layout, control); + } + } +} + +/// `control`: click the rows as the control channel's `ui.click` does (move, press and release +/// in one frame), as an agent or a live screenshot run does. +fn combine_takes_bodies_clicked_in_the_browser_in(layout: &str, control: bool) { + let mut h = crate::scenario::Harness::new(); + h.step(&json!({"call": "ui.set", "params": {"layout": layout}})).unwrap(); + h.frames(2); + h.app.run("solid.box", json!({"corner": [0, 0, 0], "length": 20, "width": 20, "height": 20, "body_name": "Block"})).unwrap(); + h.app.run("solid.box", json!({"corner": [10, 10, 10], "length": 20, "width": 20, "height": 20, "body_name": "Cutter"})).unwrap(); + h.app.session.selection.clear(); + h.app.start("solid.combine"); + h.frames(2); + for label in ["Block", "Cutter"] { + if control { + let rows = h.call("ui.handles", json!({"prefix": "row:"}))["result"].clone(); + let rows = rows.get("handles").cloned().unwrap_or(rows); + let row = rows.as_array().unwrap().iter().find(|r| r["name"] == format!("row:{label}")).cloned().unwrap(); + h.call("ui.click", json!({"x": row["x"], "y": row["y"]})); + h.frames(2); + } else { + h.step(&json!({"click": {"browser": label}})).unwrap(); + h.frames(1); + } + } + let d = h.app.dialog.as_ref().expect("Combine stays open"); + assert_eq!(d.inputs[0].items, vec![Sel::Body { name: "Block".into() }], "{layout} control={control} target: {:?}", d.inputs); + assert_eq!(d.inputs[1].items, vec![Sel::Body { name: "Cutter".into() }], "{layout} control={control} tools: {:?}", d.inputs); +}