SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Return to the originating tab after finishing a sketch (#3250) (#3264)
rlartot125b8d5387ca
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rsindex 9b5a57a060..1f93bda841 100644--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@ -263,6 +263,10 @@ pub struct UiState {pub layout: shell::LayoutMode,/// Ribbon tab; SHEET METAL and the contextual SKETCH join the seven design tabs.pub tab: String,+ /// The toolbar tab a sketch was started from; finishing the sketch goes back to it (#3250).+ /// Not saved: it only lives while a sketch is open.+ #[serde(skip)]+ pub sketch_return_tab: Option<String>,/// Last contextual body/sketch, only used to select on entry.#[serde(skip)]pub ribbon_context: Option<String>,@@ -301,6 +305,7 @@ impl Default for UiState {layout: Default::default(),tab: "MODEL".into(),ribbon_context: None,+ sketch_return_tab: None,show_browser: true,show_timeline: true,show_grid: true,diff --git a/crates/ui-egui/src/toolbar.rs b/crates/ui-egui/src/toolbar.rsindex 891f65d3d0..4ea8f286bd 100644--- a/crates/ui-egui/src/toolbar.rs+++ b/crates/ui-egui/src/toolbar.rs@@ -3137,3 +3137,42 @@ mod fill_width_tests {}}}++#[cfg(test)]+mod sketch_return_tab_tests {+ use super::*;++ /// #3250: finishing a sketch goes back to the tab it was started from, not always to MODEL.+ #[test]+ fn finishing_a_sketch_returns_to_the_tab_it_started_from() {+ for start in ["MODEL", "SURFACE", "ASSEMBLE", "INSERT", "INSPECT", "MANAGE", "VIEW"] {+ let mut h = crate::scenario::Harness::new();+ h.app.home.open = false;+ h.app.ui.tab = start.into();+ h.app.run("sketch.create", json!({"plane":"XY"})).unwrap();+ assert_eq!(h.app.ui.tab, "SKETCH", "{start}: the sketch tab shows while sketching");+ h.app.run("sketch.finish", json!({})).unwrap();+ assert!(h.app.session.active_sketch.is_none());+ assert_eq!(h.app.ui.tab, start, "{start}: back on the tab the sketch started from");+ }+ }++ /// A second sketch started from another tab returns to that tab, and a start tab that is+ /// not a normal toolbar tab (a stale name) falls back to MODEL.+ #[test]+ fn sketch_return_tab_follows_each_sketch_and_falls_back_to_model() {+ let mut h = crate::scenario::Harness::new();+ h.app.home.open = false;+ for start in ["SURFACE", "INSPECT"] {+ h.app.ui.tab = start.into();+ h.app.run("sketch.create", json!({"plane":"XY"})).unwrap();+ h.app.run("sketch.finish", json!({})).unwrap();+ assert_eq!(h.app.ui.tab, start);+ }+ let start = "NO SUCH TAB";+ h.app.ui.tab = start.into();+ h.app.run("sketch.create", json!({"plane":"XY"})).unwrap();+ h.app.run("sketch.finish", json!({})).unwrap();+ assert_eq!(h.app.ui.tab, "MODEL", "{start}: falls back to MODEL");+ }+}diff --git a/crates/ui-egui/src/workspace.rs b/crates/ui-egui/src/workspace.rsindex 00c07bc8c0..31f0f8bb30 100644--- a/crates/ui-egui/src/workspace.rs+++ b/crates/ui-egui/src/workspace.rs@@ -466,8 +466,23 @@ pub fn sync_context(app: &mut crate::SolveApp) {}let context = app.session.active_sketch.map(|id| format!("sketch:{id}")).or_else(|| sheet_body(app).map(|body| format!("sheet:{body}")));if app.ui.ribbon_context != context {+ let was_sketch = app.ui.ribbon_context.as_deref().is_some_and(|c| c.starts_with("sketch:"));+ let back = if app.session.active_sketch.is_some() {+ // Remember the tab the sketch was started from (#3250).+ if !was_sketch && app.ui.tab != "SKETCH" {+ app.ui.sketch_return_tab = Some(app.ui.tab.clone());+ }+ None+ } else if was_sketch {+ app.ui.sketch_return_tab.take()+ } else {+ None+ };app.ui.tab = if app.session.active_sketch.is_some() {"SKETCH"+ } else if let Some(back) = back.as_deref().filter(|t| *t != "SKETCH" && visible_tabs(app).contains(t)) {+ // Finishing a sketch goes back to the tab it came from (#3250).+ visible_tabs(app).into_iter().find(|t| t == &back).unwrap_or("MODEL")} else if context.is_some() {"SHEET METAL"} else {