SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Browser: Edit Feature from a component's Features folder gives the active component back (#12720) (#12723)
Mek13ab728d0705
diff --git a/crates/ui-egui/src/browser/features.rs b/crates/ui-egui/src/browser/features.rsindex 3cce4d65f4..0260e4361f 100644--- a/crates/ui-egui/src/browser/features.rs+++ b/crates/ui-egui/src/browser/features.rs@@ -339,10 +339,9 @@ fn feature_row(}}if r.double {- if !path.is_empty() {- let _ = app.run("component.activate", json!({"component":component,"occurrence":path.last(),"path":path}));- }- app.edit_feature(id);+ // Inside a placement, the feature's component is active while it is edited, and the one+ // active before comes back when the editor ends (#12720).+ app.edit_feature_in(id, Some((component, path)));} else if r.clicked {click_select(app, ui, format!("f:{id}"), Some(Sel::Feature { id }));}@@ -1008,6 +1007,87 @@ mod tests {assert!(labels.contains(&block_name), "a rolled-back feature stays listed: {labels:?}");}+ /// #12720: a feature inside a placed component, double-clicked in its Features folder, is+ /// edited with its component active, in its placement; OK and Cancel make the component active+ /// before the double-click active again, as Finish Sketch does for a sketch row (#8127). A+ /// component activated while the editor is open stays active, and a feature of the design+ /// itself activates nothing.+ #[test]+ fn a_feature_edited_from_a_placed_components_folder_gives_the_active_component_back() {+ let mut h = Harness::new();+ let plate = h.app.run("solid.box", json!({"length":60,"width":40,"height":8,"body_name":"Plate"})).unwrap()["feature"].as_u64().unwrap();+ let bracket = h.app.run("component.create", json!({"name":"Bracket","grounded":false})).unwrap();+ let pad = h.app.run("solid.box", json!({"length":20,"width":20,"height":20,"body_name":"Block"})).unwrap()["feature"].as_u64().unwrap();+ let comp = bracket["component"].as_u64().unwrap();+ let path = vec![bracket["occurrence"].as_u64().unwrap()];+ h.app.run("component.activate", json!({"component":0})).unwrap();+ h.app.run("occurrence.move", json!({"occurrence":path[0],"translate":[0,0,8]})).unwrap();+ // Find in Timeline opens the placement's rows down to the feature (and the root's folder).+ let block = h.app.session.occurrence_bodies(&path, false).unwrap()[0].clone();+ reveal(&mut h.app, pad, &block);+ h.app.tree.expanded.insert("c0/features".into());+ h.frames(2);+ let row = json!({"handle": format!("row:browser-feature:{}:{pad}", occurrence_key(&path))});+ let closed = |h: &mut Harness| {+ for _ in 0..500 {+ if h.app.dialog.is_none() && h.app.applying.is_none() && h.app.deferred.is_none() && h.app.deferred_queue.is_empty() {+ break;+ }+ h.frame();+ }+ assert!(h.app.dialog.is_none(), "{:?}", h.app.dialog.as_ref().and_then(|d| d.error.clone()));+ // Long enough that the next click is not a double or triple click.+ h.frames(40);+ };+ let active = |h: &Harness| (h.app.session.active_component, h.app.session.active_occurrence_path.clone());+ for close in ["dialog:OK", "dialog:Cancel"] {+ h.step(&json!({"click": row, "double": true})).unwrap();+ h.frames(2);+ assert!(h.app.dialog.as_ref().is_some_and(|d| d.editing.is_some_and(|(id, _)| id == pad)), "{close}: the editor opened");+ assert_eq!(active(&h), (comp, Some(path.clone())), "{close}: the bracket is active while its feature is edited");+ h.step(&json!({"click": {"handle": close}})).unwrap();+ closed(&mut h);+ assert_eq!(active(&h), (0, None), "{close}: the design is active again");+ }+ // Another command taking over ends the editor the same way.+ h.step(&json!({"click": row, "double": true})).unwrap();+ h.frames(2);+ assert_eq!(active(&h).0, comp);+ h.step(&json!({"start": "solid.box"})).unwrap();+ h.frames(2);+ assert_eq!(active(&h), (0, None), "the design is active again once another command took over");+ crate::dialogs::cancel(&mut h.app);+ h.frames(40);+ // A component activated while the editor is open stays active.+ let other = h.app.run("component.create", json!({"name":"Other"})).unwrap()["component"].as_u64().unwrap();+ h.app.run("component.activate", json!({"component":0})).unwrap();+ h.frames(2);+ h.step(&json!({"click": row, "double": true})).unwrap();+ h.frames(2);+ h.app.run("component.activate", json!({"component":other})).unwrap();+ h.step(&json!({"click": {"handle": "dialog:Cancel"}})).unwrap();+ closed(&mut h);+ assert_eq!(active(&h).0, other, "the component activated meanwhile stays active");+ // The bracket already active: editing its feature leaves it active.+ h.app.run("component.activate", json!({"component":comp,"occurrence":path[0],"path":path})).unwrap();+ h.frames(2);+ h.step(&json!({"click": row, "double": true})).unwrap();+ h.frames(2);+ h.step(&json!({"click": {"handle": "dialog:Cancel"}})).unwrap();+ closed(&mut h);+ assert_eq!(active(&h), (comp, Some(path.clone())), "a component active already stays active");+ // A feature of the design itself, edited from the root Features folder, activates nothing.+ h.app.run("component.activate", json!({"component":0})).unwrap();+ h.frames(2);+ h.step(&json!({"click": {"handle": format!("row:browser-feature:c0:{plate}")}, "double": true})).unwrap();+ h.frames(2);+ assert!(h.app.dialog.as_ref().is_some_and(|d| d.editing.is_some_and(|(id, _)| id == plate)));+ assert!(h.app.pre_edit_component.is_none());+ h.step(&json!({"click": {"handle": "dialog:Cancel"}})).unwrap();+ closed(&mut h);+ assert_eq!(active(&h), (0, None));+ }+/// #10079: three extrusions of one visible sketch, the first renamed. A click just past the end/// of a feature's name, or a press on the name that slips a few points before its release,/// selects the feature; only the sketch button itself opens the sketch.diff --git a/crates/ui-egui/src/documents.rs b/crates/ui-egui/src/documents.rsindex 47407a784a..dba1ca5690 100644--- a/crates/ui-egui/src/documents.rs+++ b/crates/ui-egui/src/documents.rs@@ -45,6 +45,7 @@ pub struct DocSlot {pub(crate) pending_feature_edit: Option<crate::feature_edit::PendingFeatureEdit>,pre_sketch_cam: Option<crate::PreSketchView>,pre_sketch_component: Option<crate::PreSketchComponent>,+ pre_edit_component: Option<crate::PreEditComponent>,view: DocView,occurrence_move: Option<crate::browser::OccMove>,reveals: crate::browser::PendingReveals,@@ -146,6 +147,7 @@ impl DocSlot {pending_feature_edit: None,pre_sketch_cam: None,pre_sketch_component: None,+ pre_edit_component: None,view: DocView::default(),occurrence_move: None,reveals: Default::default(),@@ -288,6 +290,7 @@ fn swap_in(app: &mut SolveApp, mut slot: DocSlot) -> DocSlot {pending_feature_edit: std::mem::replace(&mut app.pending_feature_edit, slot.pending_feature_edit),pre_sketch_cam: std::mem::replace(&mut app.pre_sketch_cam, slot.pre_sketch_cam),pre_sketch_component: std::mem::replace(&mut app.pre_sketch_component, slot.pre_sketch_component),+ pre_edit_component: std::mem::replace(&mut app.pre_edit_component, slot.pre_edit_component),view: take_view(app),occurrence_move: std::mem::replace(&mut app.tree.occurrence_move, slot.occurrence_move),reveals,diff --git a/crates/ui-egui/src/feature_edit.rs b/crates/ui-egui/src/feature_edit.rsindex 2d7ee5d716..053a0e6b67 100644--- a/crates/ui-egui/src/feature_edit.rs+++ b/crates/ui-egui/src/feature_edit.rs@@ -19,6 +19,11 @@ impl PendingFeatureEdit {self.next_command = None;}+ /// The feature whose editor this prepares, until the preparation is cancelled.+ pub(crate) fn feature(&self) -> Option<u64> {+ self.feature+ }+pub(crate) fn then_start(&mut self, command: &str) {self.cancel();self.next_command = Some(command.to_owned());diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rsindex aadd490e79..d4cd346e7c 100644--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@ -518,6 +518,17 @@ pub struct PreSketchComponent {pub opened_in: u64,}+/// The active component (and placement) before a feature row inside a placed component was+/// double-clicked in the Browser, which activates the feature's own component (#12720), and the+/// component the editor opened in.+#[derive(Clone, Debug, PartialEq)]+pub struct PreEditComponent {+ pub feature: u64,+ pub component: u64,+ pub path: Option<Vec<u64>>,+ pub opened_in: u64,+}+/// Which late UI handler has first refusal of this frame's Escape. Reserving input/// is distinct from having performed cancellation (`esc_handled`).#[derive(Clone, Copy, Eq, PartialEq)]@@ -563,6 +574,9 @@ pub struct SolveApp {/// 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<PreSketchComponent>,+ /// The component active before a Browser double-click activated the one a feature is in+ /// (#12720); the end of that feature's editor makes it active again.+ pub pre_edit_component: Option<PreEditComponent>,pub services: Services,file_picker: Option<file_picker::Pending>,/// A slicer started alone and waited for before the file is sent (Send to Slicer).@@ -854,6 +868,7 @@ impl SolveApp {pre_extrude_cam: None,pre_command_cam: None,pre_sketch_component: None,+ pre_edit_component: None,services,file_picker: None,slicer_wait: None,@@ -1618,6 +1633,7 @@ impl SolveApp {self.applying = None;self.editing_state = None;self.pending_feature_edit = None;+ self.pre_edit_component = None;// So does what it had computing: none of it may land in the new design.self.cancel_computing();self.tool = None;@@ -2350,6 +2366,48 @@ impl SolveApp {self.edit_feature_at(id, None);}+ /// [`Self::edit_feature`] from a feature row inside one placement of a component (the+ /// Browser's Features folder): that component is active while the feature is edited, so the+ /// edit happens in its placement, and the one active before comes back when the editor ends+ /// (#12720), as a sketch opened the same way does (#8127). A feature of the design itself, or+ /// of the component already active, is edited as it is.+ pub fn edit_feature_in(&mut self, id: u64, placement: Option<(u64, &[u64])>) {+ let Some((component, path)) = placement.filter(|(_, path)| !path.is_empty()) else {+ self.edit_feature(id);+ return;+ };+ // An editor still open from an earlier double-click ends first, giving back its own+ // component, so the one remembered here is the one the user sees before this click.+ dialogs::cancel(self);+ self.return_from_feature_edit();+ let context = (self.session.active_component, self.session.active_occurrence_path.clone());+ let _ = self.run("component.activate", json!({"component": component, "occurrence": path.last(), "path": path}));+ let opened_in = self.session.active_component;+ let moved = (opened_in, &self.session.active_occurrence_path) != (context.0, &context.1);+ self.pre_edit_component = moved.then_some(PreEditComponent { feature: id, component: context.0, path: context.1, opened_in });+ self.edit_feature(id);+ // Nothing opened (a feature without an editor goes to the command palette): the+ // component comes back at once.+ self.return_from_feature_edit();+ }++ /// Once the editor of the feature a Browser double-click activated a component for has ended,+ /// however it ended (OK, Cancel, another command, a sketch finished), the component active+ /// before the double-click is active again (#12720). Unless another component was activated+ /// meanwhile: that one stays, as after a sketch.+ fn return_from_feature_edit(&mut self) {+ let Some(id) = self.pre_edit_component.as_ref().map(|pre| pre.feature) else { return };+ let open = self.dialog.as_ref().is_some_and(|d| d.editing.is_some_and(|(feature, _)| feature == id))+ || self.pending_feature_edit.as_ref().is_some_and(|pending| pending.feature() == Some(id))+ || self.session.active_sketch == Some(id);+ if open {+ return;+ }+ if let Some(pre) = self.pre_edit_component.take().filter(|pre| pre.opened_in == self.session.active_component) {+ self.restore_component(pre.component, pre.path);+ }+ }+/// [`Self::edit_feature`] opened from a click at `at` on what the feature made: the dialog's/// arrow sits by that point (a fillet's or chamfer's edge nearest it).pub(crate) fn edit_feature_at(&mut self, id: u64, at: Option<solidcore_record::Vec3>) {@@ -3222,6 +3280,7 @@ impl SolveApp {self.drain_control(ctx);self.follow_view_request(true);self.return_from_extrude_view();+ self.return_from_feature_edit();agent_cursor::step(self, ctx);browser::eye_drag_frame(self, ctx);if !self.synthetic.is_empty() || !self.held_click.is_empty() {