SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Move shortcut respects the selected component (#3580) (#3588)
Colin Faulkinghamb66ad0a9c9b8
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rsindex 37b6c20fa8..9c8c3246c5 100644--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@ -850,6 +850,17 @@ impl SolveApp {return;}workspace::select_command_tab(self, id);+ // Move a selected assembly placement the same way as its Browser menu, retaining+ // the exact instance path and the grounding/rigid-group restrictions.+ if id == "solid.move"+ && let [solidcraft_engine::Sel::Occurrence { path }] = self.session.selection.as_slice()+ {+ let target = context_menu::Target::Occurrence { path: path.clone() };+ if let Some(item) = context_menu::items(self, &target).into_iter().find(|item| item.id == "ui.moveOccurrence") {+ context_menu::run_item(self, &item, egui::Pos2::ZERO);+ }+ return;+ }if id == "material.properties.validate" {self.material_card_review = Some(material_card_review::ReviewWindow::default());self.home.open = false;diff --git a/crates/ui-egui/src/menu_tests.rs b/crates/ui-egui/src/menu_tests.rsindex 26830b3e5b..9ed2558521 100644--- a/crates/ui-egui/src/menu_tests.rs+++ b/crates/ui-egui/src/menu_tests.rs@@ -261,6 +261,53 @@ fn component_menu_activates_grounds_and_pastes() {assert_eq!(app.session.doc.components.len(), 2);}+#[test]+fn move_shortcut_uses_the_selected_nested_instance_and_pending_position() {+ let mut app = SolveApp::new(Session::default(), Services::default());+ let parent = app.run("component.create", json!({"name":"Assembly"})).unwrap()["occurrence"].as_u64().unwrap();+ let child = app.run("component.create", json!({"name":"Carriage"})).unwrap()["occurrence"].as_u64().unwrap();+ app.run("solid.box", json!({"length":30,"width":20,"height":10})).unwrap();+ let copy = app.run("occurrence.copy", json!({"occurrence":parent,"translate":[100,0,0]})).unwrap()["occurrence"].as_u64().unwrap();+ let path = vec![copy, child];+ app.run("component.activate", json!({"component":"root"})).unwrap();+ app.run("occurrence.move", json!({"occurrence":child,"path":path,"translate":[5,0,0],"capture":false})).unwrap();+ let baseline = app.session.pending_moves[&child];+ app.run("select.set", json!({"items":[{"type":"occurrence","path":path}]})).unwrap();+ crate::keymap::bind(&mut app, "solid.move", "Shift+M", false).unwrap();+ crate::keymap::press(&mut app, "M");+ assert!(app.tree.occurrence_move.is_none(), "the old shortcut was cleared");+ app.ui.tab = "INSPECT".into();+ crate::keymap::press(&mut app, "Shift+M");+ assert_eq!(app.ui.tab, "MODEL", "starting component Move still selects the command's workspace tab");+ let movement = app.tree.occurrence_move.as_ref().expect("component Move opens from its rebound shortcut");+ assert_eq!(movement.occurrence, child);+ assert_eq!(movement.path, path, "use the selected copy's path, not the component's first placement");+ assert_eq!(movement.baseline, Some(baseline));+ assert!(movement.had_pending);+ assert!(app.dialog.is_none(), "the body Move dialog must not open too");+ assert!(app.tree.capture_prompt.is_none(), "continuing a component move does not ask to capture it first");+}++#[test]+fn move_shortcut_respects_grounding_and_keeps_body_selection_as_a_body_move() {+ let mut app = SolveApp::new(Session::default(), Services::default());+ let occurrence = app.run("component.create", json!({"name":"Carriage"})).unwrap()["occurrence"].as_u64().unwrap();+ app.run("solid.box", json!({"length":30,"width":20,"height":10})).unwrap();+ app.run("occurrence.ground", json!({"occurrence":occurrence,"grounded":true})).unwrap();+ app.run("select.set", json!({"items":[{"type":"occurrence","path":[occurrence]}]})).unwrap();+ crate::keymap::press(&mut app, "M");+ assert!(app.tree.occurrence_move.is_none(), "a grounded component cannot move");+ assert!(app.dialog.is_none(), "do not fall back to moving the grounded component's bodies");++ app.run("occurrence.ground", json!({"occurrence":occurrence,"grounded":false})).unwrap();+ app.run("select.set", json!({"items":[{"type":"body","name":"Body1"}]})).unwrap();+ crate::keymap::press(&mut app, "M");+ assert!(app.tree.occurrence_move.is_none(), "a body selection still edits geometry");+ let dialog = app.dialog.as_ref().expect("body Move opens");+ assert!(matches!(dialog.kind, crate::dialogs::Kind::Move { .. }));+ assert_eq!(dialog.inputs[0].items, vec![solidcraft_engine::Sel::Body { name: "Body1".into() }]);+}+#[test]fn pick_runs_an_item_of_the_open_menu() {let mut app = sample_app();diff --git a/crates/ui-egui/src/sketch_shortcut_tests.rs b/crates/ui-egui/src/sketch_shortcut_tests.rsindex 5a6481dc67..7be7f41d7c 100644--- a/crates/ui-egui/src/sketch_shortcut_tests.rs+++ b/crates/ui-egui/src/sketch_shortcut_tests.rs@@ -123,3 +123,28 @@ fn construction_key_outside_a_sketch_opens_nothing_and_keys_in_a_sketch_keep_it(assert_eq!(h.app.session.world_state().sketches.len(), 1);assert_eq!(tool(&h), Some("sketch.circle.center"));}++#[test]+fn move_key_keeps_sketch_mode_behavior_and_honors_a_sketch_move_binding() {+ let mut h = Harness::new();+ h.app.run("component.create", json!({"name":"Carriage"})).unwrap();+ h.app.run("sketch.create", json!({"plane":"XY"})).unwrap();+ h.app.run("sketch.line", json!({"points":[[0,0],[10,0]]})).unwrap();+ let sketch = h.app.session.active_sketch;+ let selection = vec![Sel::SketchCurve { id: "l1".into() }];+ h.app.session.selection = selection.clone();++ press(&mut h, "M");+ assert!(h.app.dialog.is_none(), "the default body Move shortcut is disabled in a sketch");+ assert!(h.app.tree.occurrence_move.is_none());+ assert_eq!(h.app.session.active_sketch, sketch);+ assert_eq!(h.app.session.selection, selection);++ crate::keymap::bind(&mut h.app, "sketch.move", "M", true).unwrap();+ press(&mut h, "M");+ let dialog = h.app.dialog.as_ref().expect("a rebound M opens Sketch Move in an active sketch");+ assert!(matches!(dialog.kind, crate::dialogs::Kind::SketchModify(crate::sketch_modify_ui::Mod::Move { .. })));+ assert_eq!(dialog.inputs[0].items, selection);+ assert_eq!(h.app.session.active_sketch, sketch);+ assert!(h.app.tree.occurrence_move.is_none(), "M must not open component Move while editing its sketch");+}diff --git a/crates/ui-egui/tests/scenarios/s34_component_move_carries_sketches.json b/crates/ui-egui/tests/scenarios/s34_component_move_carries_sketches.jsonindex 7d48038de6..fe08e28f15 100644--- a/crates/ui-egui/tests/scenarios/s34_component_move_carries_sketches.json+++ b/crates/ui-egui/tests/scenarios/s34_component_move_carries_sketches.json@@ -1,6 +1,6 @@[{- "note": "User bug 4 (owner solidcraft-repo): moving a component carries its sketches, and a sketch on a body face follows the body."+ "note": "Moving a component with the Browser's Move shortcut carries its sketches, and a sketch on a body face follows the body (#3580)."},{"start": "component.create"@@ -120,21 +120,12 @@}},{- "call": "ui.menu",- "params": {- "x": 100,- "y": 170,- "target": {- "type": "component",- "id": 1- }+ "click": {+ "handle": "row:occurrence:2"}},{- "call": "ui.menuPick",- "params": {- "item": "Move/Copy"- }+ "key": "M"},{"widget": "0.00 mm",