diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 21683ceb4..19ad180eb 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -527,6 +527,9 @@ pub struct SolveApp { /// The view from before Extrude turned it to isometric (#9176); the view goes back to it when /// the dialog closes, as the "and back when it closes" preference says. pub pre_extrude_cam: Option, + /// The view a command that ends an open sketch was clicked in (#10571), taken before the + /// sketch's own end turns the view: that turn must not become the view Extrude goes back to. + pre_command_cam: Option, /// The component active before Edit Sketch activated the one the sketch is in (#8127); /// leaving the sketch makes it active again. pub pre_sketch_component: Option, @@ -789,6 +792,7 @@ impl SolveApp { now: 0.0, pre_sketch_cam: None, pre_extrude_cam: None, + pre_command_cam: None, pre_sketch_component: None, services, file_picker: None, @@ -1899,6 +1903,9 @@ impl SolveApp { dialogs::cancel(self); } let finished_sketch = self.session.active_sketch.filter(|_| ends_sketch(id) && self.interactive(id)); + // The sketch's end may turn the view (Preferences › Sketch); Extrude goes back to the view + // it was clicked in, so take that one before the turn starts (#10571). + self.pre_command_cam = finished_sketch.is_some().then(|| self.settled_cam()); if finished_sketch.is_some() { self.finish_sketch(); // A feature committed before the marker is back would go in where the sketch was. @@ -2200,7 +2207,7 @@ impl SolveApp { if !self.preferences.extrude_view_isometric { return; } - let before = self.settled_cam(); + let before = self.pre_command_cam.take().unwrap_or_else(|| self.settled_cam()); let mut to = before; to.set_view(StandardView::Iso); self.pre_extrude_cam = self.preferences.extrude_view_return.then_some(before); diff --git a/crates/ui-egui/src/sketch_edit_tests.rs b/crates/ui-egui/src/sketch_edit_tests.rs index 792d793ab..ace851042 100644 --- a/crates/ui-egui/src/sketch_edit_tests.rs +++ b/crates/ui-egui/src/sketch_edit_tests.rs @@ -640,6 +640,29 @@ mod extrude_view_preference { assert_eq!(h.app.cam, iso_of(top), "{close}: isometric again"); } } + + /// #10571: Extrude clicked with the sketch still open ends the sketch on its way, and that + /// end turns the view back where it opened (Preferences › Sketch). The turn must not become + /// the view Extrude goes back to: it is the view the command was clicked in. + #[test] + fn extrude_from_an_open_sketch_goes_back_to_the_view_it_was_clicked_in() { + let mut h = Harness::new(); + h.app.preferences.extrude_view_isometric = true; + h.app.preferences.extrude_view_return = true; + h.app.preferences.sketch_exit_view = crate::prefs::SketchExitView::Previous; + h.app.run("sketch.create", json!({"plane": "XY"})).unwrap(); + h.app.run("sketch.rectangle.two_point", json!({"p0": [0, 0], "p1": [40, 30]})).unwrap(); + h.call("ui.view", json!({"view": "top"})); + h.settle(); + let top = h.app.cam; + open_extrude(&mut h); + assert_eq!(h.app.cam, iso_of(top), "isometric while Extrude is open"); + h.step(&json!({"widget": "Cancel"})).unwrap(); + h.settle(); + assert!(h.app.dialog.is_none()); + assert_eq!(h.app.session.active_sketch, None, "Extrude ended the sketch"); + assert_eq!(h.app.cam, top, "back to the sketch view it was clicked in"); + } } /// #8127: a sketch inside an inserted fastener, opened from its row in the browser, activates the