Move/Copy: a triad drag ends where the button is released (#8265) (#8309)

* 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.
This commit is contained in:
Colin Faulkingham
2026-10-28 16:53:41 +00:00
committed by GitHub
parent dd2e44bb12
commit 95ba99d710
2 changed files with 54 additions and 1 deletions
+37
View File
@@ -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");
}
+17 -1
View File
@@ -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::<State>(id));
} else {