From 95ba99d710a314faec2f6152839181bd4be5b13b Mon Sep 17 00:00:00 2001 From: Colin Faulkingham Date: Wed, 28 Oct 2026 16:53:41 +0000 Subject: [PATCH] Move/Copy: a triad drag ends where the button is released (#8265) (#8309) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * claim: #8265 * Move/Copy: a triad drag ends where the button was released (#8265) A frame carries all the input queued since the last one, so the release that ends a drag and further pointer movement — the hand keeps moving as the button goes up, or input is queued during a busy frame — arrive together, and the frame's latest pointer position is already past the release. The drag's final change was read from it, so the value, the preview and the command both jumped to wherever the mouse had got to; pressing Enter right after the release closed the window first, which is why that worked around it. Rotate and occurrence moves share the triad. The final change now comes from the release event's own position, which the raw input carries (egui's processed pointer events drop it). The regression test sends a release at 20 mm and a move to 30 mm in one frame: 30 mm before, 20 mm after. Fixes #8265. --- crates/ui-egui/src/dialogs_move_tests.rs | 37 ++++++++++++++++++++++++ crates/ui-egui/src/gizmo.rs | 18 +++++++++++- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/dialogs_move_tests.rs b/crates/ui-egui/src/dialogs_move_tests.rs index 5dcd45b13..369952fd7 100644 --- a/crates/ui-egui/src/dialogs_move_tests.rs +++ b/crates/ui-egui/src/dialogs_move_tests.rs @@ -414,3 +414,40 @@ fn a_body_pick_goes_on_to_the_point_or_axis() { assert_eq!(d.inputs[0].items.len(), 1, "the body is still picked"); assert!(matches!(d.inputs[1].items.as_slice(), [Sel::Vertex { .. }]), "{:?}", d.inputs[1].items); } + +/// #8265: input queued while the window is busy arrives together, so one frame can carry the +/// button let go and the mouse already moving on. The drag must end where the button was +/// released, not jump the value to where the mouse has since got to. +#[test] +fn triad_drag_ends_where_the_button_was_released() { + let mut h = crate::scenario::Harness::new(); + h.app.run("solid.box", json!({"length": 20, "width": 30, "height": 10})).unwrap(); + h.app.start("solid.move"); + { + let d = h.app.dialog.as_mut().unwrap(); + d.inputs[0].items = vec![Sel::Body { name: "Body1".into() }]; + } + h.frames(3); + let pos = |p: [f64; 2]| egui::pos2(p[0] as f32, p[1] as f32); + let button = |p: [f64; 2], pressed: bool| egui::Event::PointerButton { + pos: pos(p), + button: egui::PointerButton::Primary, + pressed, + modifiers: Default::default(), + }; + let grip = h.at(&json!({"gizmo": "x"})).unwrap(); + let released = h.at(&json!({"gizmo": "x", "by": [20.0, 0.0, 0.0]})).unwrap(); + let later = h.at(&json!({"gizmo": "x", "by": [30.0, 0.0, 0.0]})).unwrap(); + let value = |h: &crate::scenario::Harness| match &h.app.dialog.as_ref().unwrap().kind { + Kind::Move { x, .. } => x.clone(), + other => panic!("not a move: {other:?}"), + }; + // Hover the arrow, press it, then drag 20 mm along it. + h.frame_with(vec![egui::Event::PointerMoved(pos(grip))]); + h.frame_with(vec![button(grip, true)]); + h.frame_with(vec![egui::Event::PointerMoved(pos(released))]); + assert_eq!(value(&h), "20 mm", "the drag follows the pointer"); + // The button is let go and the mouse already moves on: one frame carries both. + h.frame_with(vec![button(released, false), egui::Event::PointerMoved(pos(later))]); + assert_eq!(value(&h), "20 mm", "the drag ends where the button was released"); +} diff --git a/crates/ui-egui/src/gizmo.rs b/crates/ui-egui/src/gizmo.rs index 26a4675ff..33e219765 100644 --- a/crates/ui-egui/src/gizmo.rs +++ b/crates/ui-egui/src/gizmo.rs @@ -348,6 +348,23 @@ pub fn show(ui: &mut egui::Ui, painter: &egui::Painter, proj: &Proj, id: egui::I s } }; + let done = r.drag_stopped() || !r.dragged() && !started; + // The frame's events can hold the release and further movement — the hand keeps moving as + // the button goes up, or input queued during a busy frame — and `p` is already past the + // release then. The release event itself carries where the button was let go (#8265): take + // the final change from there, so the drag ends where the button was released, not where + // the mouse has since got to. + let p = if done { + ui.input(|i| { + i.events.iter().find_map(|e| match e { + egui::Event::PointerButton { pos, pressed: false, .. } => Some(*pos), + _ => None, + }) + }) + .unwrap_or(p) + } else { + p + }; let change = match st.handle { Handle::Axis(i) => { let v = along(proj, p, st.center, DIRS[i]).map(|v| v - st.t0).unwrap_or(0.0); @@ -374,7 +391,6 @@ pub fn show(ui: &mut egui::Ui, painter: &egui::Painter, proj: &Proj, id: egui::I Change::Translate(Vec3::new(snap(d.x, step, free), snap(d.y, step, free), snap(d.z, step, free))) } }; - let done = r.drag_stopped() || !r.dragged() && !started; if done { ui.data_mut(|d| d.remove::(id)); } else {