From f87dd73661288bb806342bc6f7c50b413050158f Mon Sep 17 00:00:00 2001 From: thocsmith Date: Wed, 4 Nov 2026 22:23:02 +0000 Subject: [PATCH] Selection filter: from command search it offers Faces, Bodies, Components (#11505) (#11553) * claim: #11505 * Selection filter: started from command search, it offers Faces, Bodies, Components (#11505) Command search ran select.filter with no parameters, which could only fail with "missing field `mode`". Started from the UI (command search, a shortcut, ui.start), it now opens its three modes as a menu with the current one marked, as View > Visual style and Navigation tool do (#8868). Programmatic calls keep their contract and open nothing. Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: thocsmith <193096300+thocsmith@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 --- crates/ui-egui/src/context_menu.rs | 47 ++++++++++++++++++++++++++++++ crates/ui-egui/src/lib.rs | 3 +- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/context_menu.rs b/crates/ui-egui/src/context_menu.rs index 3a5246f48..30ead1412 100644 --- a/crates/ui-egui/src/context_menu.rs +++ b/crates/ui-egui/src/context_menu.rs @@ -72,6 +72,8 @@ pub enum Target { VisualStyle, /// View › Navigation tool: Orbit, Pan, Zoom; the latched one marked (#8868). ViewTool, + /// Selection filter: Faces, Bodies, Components; the current one marked (#11505). + SelectionFilter, /// The mouse mappings (Preferences › Navigation), from the status bar (#7023). Navigation, /// An assembly joint. @@ -484,6 +486,15 @@ pub fn items(app: &SolveApp, target: &Target) -> Vec { }) .collect() } + Target::SelectionFilter => { + let mode = app.ui.pick_mode(); + [("face", "Faces"), ("body", "Bodies"), ("component", "Components")] + .into_iter() + .map(|(choice, label)| { + cmd(app, "select.filter", label).with(json!({"mode": choice})).key(if mode == choice { "current" } else { "" }) + }) + .collect() + } }; if !crate::render_workspace::active(app) { v.extend(crate::browser::folded_folder_items(app, target)); @@ -2838,6 +2849,42 @@ mod tests { assert!(!error(&h)); } + #[test] + fn selection_filter_from_command_search_offers_its_modes_not_a_missing_mode_error() { + // #11505: command search started select.filter with no parameters, which could only fail. + let mut h = crate::scenario::Harness::new(); + h.app.home.open = false; + h.app.status = None; + let error = |h: &crate::scenario::Harness| h.app.status.as_ref().is_some_and(|(_, _, error)| *error); + h.app.start("select.filter"); + assert!(!error(&h), "{:?}", h.app.status); + assert_eq!(h.app.menu.target, Target::SelectionFilter); + assert!(h.app.viewport.context_menu.is_some()); + let menu = describe(&h.app); + let labels: Vec<_> = menu["items"].as_array().unwrap().iter().map(|i| i["label"].as_str().unwrap().to_owned()).collect(); + assert_eq!(labels, ["Faces", "Bodies", "Components"]); + let current = |h: &crate::scenario::Harness| { + items(&h.app, &Target::SelectionFilter).into_iter().filter(|i| i.shortcut == "current").map(|i| i.label).collect::>() + }; + assert_eq!(current(&h), ["Faces"]); + h.call("ui.menuPick", json!({"item":"Bodies"})); + assert!(h.app.ui.pick_bodies && !h.app.ui.pick_components); + assert!(h.app.viewport.context_menu.is_none()); + assert!(!error(&h), "{:?}", h.app.status); + h.call("ui.start", json!({"command":"select.filter"})); + assert_eq!(current(&h), ["Bodies"]); + h.call("ui.menuPick", json!({"item":"Components"})); + assert!(h.app.ui.pick_components && !h.app.ui.pick_bodies); + h.app.start("select.filter"); + h.call("ui.menuPick", json!({"item":"Faces"})); + assert!(!h.app.ui.pick_components && !h.app.ui.pick_bodies); + assert!(!error(&h), "{:?}", h.app.status); + // Programmatic calls keep their contract: no parameters is still refused, and opens no menu. + let missing = h.call("engine.execute", json!({"command":"select.filter","params":{}})); + assert_eq!(missing["ok"], false); + assert!(h.app.viewport.context_menu.is_none()); + } + #[test] fn line_offset_context_menu_breaks_association_and_allows_trim() { use solidcore_record::Vec2; diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index de9623c6b..d61677571 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -1740,11 +1740,12 @@ impl SolveApp { return; } // A display choice opens its choices, as the navigation bar's menus do: run with no - // parameters it could only fail (#8868). The choices menu is not the command's ribbon + // parameters it could only fail (#8868); so does the selection filter's mode (#11505). The choices menu is not the command's ribbon // place, so the ribbon keeps its tab however the menu was opened (#10540). let choice = match id { "view.visual_style" => Some(context_menu::Target::VisualStyle), "view.tool" => Some(context_menu::Target::ViewTool), + "select.filter" => Some(context_menu::Target::SelectionFilter), _ => None, }; if let Some(target) = choice {