Return to the originating tab after finishing a sketch (#3250) (#3264)

* claim: #3250

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* Return to the originating toolbar tab after finishing a sketch (#3250)

A sketch started from SHEET METAL or PLASTIC always ended on the SOLID
tab. Remember the tab that was active when the sketch began
(UiState::sketch_return_tab, not saved) and go back to it when the
sketch ends. Falls back to SOLID when that is not one of the normal
toolbar tabs. A sketch started from SOLID behaves as before.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* Test: no one-element loop in the return-tab test (clippy single_element_loop)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
rlartot
2026-10-23 14:31:48 +00:00
committed by GitHub
parent b5edd98bc9
commit 125b8d5387
3 changed files with 59 additions and 0 deletions
+5
View File
@@ -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,
+39
View File
@@ -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");
}
}
+15
View File
@@ -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 {