From d366b8922aa0061d92472a2fec4d649045b6ff8c Mon Sep 17 00:00:00 2001 From: Colin Faulkingham Date: Sun, 25 Oct 2026 01:25:33 +0000 Subject: [PATCH] Keep the main sketch tool unchanged when a pinned tool starts (#4023) (#6013) * claim: #4023 * fix(ui): preserve sketch family choices when starting pinned tools --- crates/ui-egui/src/lib.rs | 12 ++++++++++- crates/ui-egui/src/sketch_families.rs | 30 +++++++++++++++++++++++++++ crates/ui-egui/src/toolbar.rs | 2 +- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index e9e017d0b..a982a14a7 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -939,6 +939,16 @@ impl SolveApp { /// Start a command the way a toolbar click does: interactive tools and dialogs for commands /// that have them, otherwise run it with defaults. pub fn start(&mut self, id: &str) { + self.start_with_variant_memory(id, true); + } + + /// A dedicated toolbar button starts its exact tool without replacing the sketch family's + /// main button. Choosing a variant from a menu still uses `start` and remembers that choice. + pub(crate) fn start_pinned(&mut self, id: &str) { + self.start_with_variant_memory(id, false); + } + + fn start_with_variant_memory(&mut self, id: &str, remember_variant: bool) { if id == "ui.palette" { shortcut_box::open(self, None); return; @@ -1061,7 +1071,7 @@ impl SolveApp { if !sketch_tools::start_hook(self, id) { return; } - if solidcraft_engine::find_command(id).is_some_and(|c| c.info(&self.session).enabled) { + if remember_variant && solidcraft_engine::find_command(id).is_some_and(|c| c.info(&self.session).enabled) { self.preferences.sketch_variants.remember(id); } if id == "parameters.change" { diff --git a/crates/ui-egui/src/sketch_families.rs b/crates/ui-egui/src/sketch_families.rs index f31efa245..ac3feeeef 100644 --- a/crates/ui-egui/src/sketch_families.rs +++ b/crates/ui-egui/src/sketch_families.rs @@ -130,6 +130,36 @@ mod tests { assert_eq!(restored.preferences.sketch_variants.resolve("sketch.rectangle.two_point"), "sketch.rectangle.three_point"); } + #[test] + fn pinned_sketch_variants_leave_the_family_choice_to_its_menu() { + use serde_json::json; + + for (main, pinned, menu_choice) in [ + ("sketch.rectangle.two_point", "sketch.rectangle.center", "sketch.rectangle.three_point"), + ("sketch.circle.center", "sketch.circle.two_point", "sketch.circle.three_point"), + ] { + let mut h = crate::scenario::Harness::new(); + h.app.run("sketch.create", json!({"plane":"XY"})).unwrap(); + crate::toolbar_custom::pin(&mut h.app, "SKETCH", pinned).unwrap(); + h.settle(); + let f = family(main).unwrap(); + + for expected in [main, menu_choice] { + if expected == menu_choice { + h.step(&json!({"click":{"handle":format!("family:{}", f.label)}})).unwrap(); + h.step(&json!({"click":{"handle":format!("dropdown:{menu_choice}")}})).unwrap(); + assert_eq!(h.app.tool.as_ref().map(|t| t.cmd), Some(menu_choice)); + } + h.step(&json!({"click":{"handle":format!("button:{pinned}")}})).unwrap(); + assert_eq!(h.app.tool.as_ref().map(|t| t.cmd), Some(pinned), "the pin starts its exact tool"); + assert_eq!(h.app.preferences.sketch_variants.resolve(main), expected, "the pin leaves the family choice alone"); + + h.step(&json!({"click":{"handle":format!("button:{main}")}})).unwrap(); + assert_eq!(h.app.tool.as_ref().map(|t| t.cmd), Some(expected), "the main button still starts the chosen variant"); + } + } + } + #[test] fn old_or_damaged_prefs_fall_back_to_each_familys_first_variant() { let mut app = crate::SolveApp::new(Default::default(), Default::default()); diff --git a/crates/ui-egui/src/toolbar.rs b/crates/ui-egui/src/toolbar.rs index e7dbde749..d6d08ff4e 100644 --- a/crates/ui-egui/src/toolbar.rs +++ b/crates/ui-egui/src/toolbar.rs @@ -1288,7 +1288,7 @@ pub fn toolbar(app: &mut SolveApp, ui: &mut egui::Ui) { resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, ui.is_enabled() && info.enabled, &tr_label)); if ribbon_tooltip(app, resp, selected, info.disabled_reason.as_deref()).clicked() && info.enabled { let id = selected.id; - app.start(id); + app.start_pinned(id); } if let Some(f) = family { let ar = if labels {