SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Fix Touchpad navigation with focused tool fields (#10231) (#10253)
Colin Faulkinghambda8b6b2e8d0
diff --git a/crates/ui-egui/src/navigation.rs b/crates/ui-egui/src/navigation.rsindex fc91c75c2d..e2e65a85d7 100644--- a/crates/ui-egui/src/navigation.rs+++ b/crates/ui-egui/src/navigation.rs@@ -366,6 +366,7 @@ fn zoom_point(app: &mut SolveApp, rect: Rect, point: Option<Pos2>, surface: bool}/// Modifier-only navigation never borrows pointer movement from another widget or gesture.+/// Tool fields keep keyboard focus without blocking motion over the exposed viewport.pub(crate) fn modifier_motion(app: &mut SolveApp,ui: &egui::Ui,@@ -376,7 +377,6 @@ pub(crate) fn modifier_motion() -> Option<(NavMode, egui::Vec2)> {let owns = inside&& ui.input(|i| i.focused && !i.pointer.any_down() && !i.pointer.any_released() && !i.pointer.any_pressed())- && !ui.ctx().egui_wants_keyboard_input()&& !egui::Popup::is_any_open(ui.ctx())&& !crate::dim_view::editing()&& app.viewport.context_menu.is_none()diff --git a/crates/ui-egui/src/viewport.rs b/crates/ui-egui/src/viewport.rsindex 800638e05f..cf2fbd6616 100644--- a/crates/ui-egui/src/viewport.rs+++ b/crates/ui-egui/src/viewport.rs@@ -8890,6 +8890,74 @@ mod tests {}}+ #[test]+ fn touchpad_motion_with_focused_tool_fields_preserves_editing_and_pointer_ownership() {+ for command in ["solid.move", "solid.extrude"] {+ for canvas in [true, false] {+ for alt in [true, false] {+ let mut h = crate::scenario::Harness::new();+ h.app.preferences.nav = "touchpad".into();+ h.app.preferences.value_boxes_in_view = canvas;+ if command == "solid.move" {+ h.app.run("solid.box", json!({"length":30,"width":20,"height":10})).unwrap();+ h.app.session.selection = vec![Sel::Body { name: "Body1".into() }];+ } else {+ 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.app.run("sketch.finish", json!({})).unwrap();+ let sketch = h.app.session.doc.features[0].id;+ h.app.session.selection = vec![Sel::Profile { sketch, index: 0 }];+ }+ h.step(&json!({"start":command})).unwrap();+ h.frames(6);+ let focus = h.ctx.memory(|m| m.focused()).expect("the tool's value field has focus");+ assert!(h.ctx.egui_wants_keyboard_input());+ let doc = h.app.session.doc.to_json();+ let undo = h.app.session.undo.len();+ let values = format!("{:?}", h.app.dialog.as_ref().unwrap().kind);+ h.call("ui.move", json!({"x":600,"y":350}));+ let before = h.app.cam;+ h.call("ui.move", json!({"x":600,"y":350,"alt":alt,"shift":!alt}));+ h.call("ui.move", json!({"x":660,"y":390,"alt":alt,"shift":!alt}));+ if alt {+ assert!((h.app.cam.yaw - before.yaw - 0.48).abs() < 1e-6, "{command}, canvas={canvas}: a focused field must allow orbit");+ assert_eq!(h.app.cam.target, before.target);+ } else {+ assert_ne!(h.app.cam.target, before.target, "{command}, canvas={canvas}: a focused field must allow pan");+ assert_eq!(h.app.cam.yaw, before.yaw);+ }+ assert_eq!(h.app.cam.distance, before.distance);+ assert_eq!(h.ctx.memory(|m| m.focused()), Some(focus), "navigation must keep the field focused");++ // The field owns pointer motion over itself, even while its keyboard focus+ // no longer blocks navigation elsewhere. Leaving it must rearm without a jump.+ let at = h.ctx.read_response(focus).unwrap().rect.center();+ let moved = h.app.cam;+ h.call("ui.move", json!({"x":at.x,"y":at.y,"alt":alt,"shift":!alt}));+ h.call("ui.move", json!({"x":at.x+1.0,"y":at.y,"alt":alt,"shift":!alt}));+ assert_eq!(h.app.cam, moved, "pointer motion over a field must stay with the field");+ h.call("ui.move", json!({"x":600,"y":350,"alt":alt,"shift":!alt}));+ assert_eq!(h.app.cam, moved, "returning to the viewport must not jump");+ h.call("ui.move", json!({"x":605,"y":350,"alt":alt,"shift":!alt}));+ assert_ne!(h.app.cam, moved, "navigation resumes after leaving the field");+ let resumed = h.app.cam;+ h.call("ui.move", json!({"x":600,"y":350}));+ h.frames(3);+ assert_eq!(h.app.cam, resumed, "releasing the modifier ends navigation");+ assert_eq!(format!("{:?}", h.app.dialog.as_ref().unwrap().kind), values);+ assert_eq!(h.app.session.doc.to_json(), doc);+ assert_eq!(h.app.session.undo.len(), undo);+ assert_eq!(h.ctx.memory(|m| m.focused()), Some(focus));++ h.call("ui.key", json!({"key":"A","cmd":true}));+ h.call("ui.text", json!({"text":"7"}));+ assert_eq!(h.app.dialog.as_mut().unwrap().primary().unwrap().2.as_str(), "7", "typing still reaches the focused field");+ assert_eq!(h.app.cam, resumed);+ }+ }+ }+ }+#[test]fn touchpad_motion_uses_the_effective_perspective_projection() {let mut app = hover_app(false);