From 435d47adad1c2289704fd5faefcdb8b90d10e373 Mon Sep 17 00:00:00 2001 From: Hector Villarreal Date: Sun, 25 Oct 2026 09:35:37 -0600 Subject: [PATCH] Hue/Saturation: a range drag released in its move frame still lands CodeRabbit on #9272: when the pointer moves and lets go between two frames, the release frame isn't 'button down', so the zone drag skipped the final position and committed the bounds from before the move. The release frame now applies its position, for zone and handle drags alike. Test: a_zone_drag_released_in_the_frame_it_moves_still_moves Co-Authored-By: Claude Opus 5.5 --- .../dialogs/adjust_editors/hue_saturation.rs | 11 ++--- .../src/dialogs/adjust_editors/ui_tests.rs | 47 +++++++++++++++++++ 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/crates/ui-egui/src/dialogs/adjust_editors/hue_saturation.rs b/crates/ui-egui/src/dialogs/adjust_editors/hue_saturation.rs index 777ccf4a390..0ec35487985 100644 --- a/crates/ui-egui/src/dialogs/adjust_editors/hue_saturation.rs +++ b/crates/ui-egui/src/dialogs/adjust_editors/hue_saturation.rs @@ -246,9 +246,10 @@ pub(super) fn hue_saturation(ui: &mut egui::Ui, v: &mut Value, cx: &EditorCx) -> which = hue_range_handle_at(b.map(xof), pos.x, w); zone = if which.is_none() { hue_range_zone(b, deg_of(pos.x)).map(|z| (z, b, pos.x)) } else { None }; } - if bresp.is_pointer_button_down_on() - && let (Some((z, start, x0)), Some(pos)) = (zone, ui.input(|i| i.pointer.interact_pos())) - { + // The release frame applies its position too: a move and a release that land in one frame + // would otherwise commit the bounds from before the move. + let live = bresp.is_pointer_button_down_on() || ui.input(|i| i.pointer.primary_released()); + if live && let (Some((z, start, x0)), Some(pos)) = (zone, ui.input(|i| i.pointer.interact_pos())) { let before = b; b = move_hue_range_zone(start, z, (pos.x - x0) / w * 360.0); if b != before { @@ -261,9 +262,7 @@ pub(super) fn hue_saturation(ui: &mut egui::Ui, v: &mut Value, cx: &EditorCx) -> e.commit = true; } ui.data_mut(|d| d.insert_temp(zone_id, zone)); - if bresp.is_pointer_button_down_on() - && let (Some(k), Some(pos)) = (which, ui.input(|i| i.pointer.interact_pos())) - { + if live && let (Some(k), Some(pos)) = (which, ui.input(|i| i.pointer.interact_pos())) { let k = k as usize; let deg = deg_of(pos.x); let before = b; diff --git a/crates/ui-egui/src/dialogs/adjust_editors/ui_tests.rs b/crates/ui-egui/src/dialogs/adjust_editors/ui_tests.rs index 68b9793d5a2..c0d550bcf84 100644 --- a/crates/ui-egui/src/dialogs/adjust_editors/ui_tests.rs +++ b/crates/ui-egui/src/dialogs/adjust_editors/ui_tests.rs @@ -1024,3 +1024,50 @@ fn hue_saturation_range_zones_drag_their_handles() { assert!((b[0] - (before[0] - 18.0)).abs() <= 1.0 && (b[1] - (before[1] - 18.0)).abs() <= 1.0, "left two moved: {before:?} → {b:?}"); assert_eq!([b[2], b[3]], [before[2], before[3]], "right two stay"); } + +/// CodeRabbit on #9272: a move and release that land in the same frame still move the zone; the +/// release frame applies its position before the drag commits. +#[test] +fn a_zone_drag_released_in_the_frame_it_moves_still_moves() { + let mut h = app_harness("hueSaturation", "rgb", 8); + let (id, _) = layer(&h); + let mem = crate::adjust_editors::layer_mem(id); + h.ctx.data_mut(|d| d.insert_temp(mem.with("hs-range"), 3usize)); // Greens: 75/105…135\165 + h.run_steps(3); + let bars: Rect = h.ctx.data(|d| d.get_temp(mem.with("hs-range-bars"))).expect("the range bars"); + let x = |deg: f32| bars.left() + deg / 360.0 * bars.width(); + let y = bars.center().y; + let steps = h.state().session.active().unwrap().history.past_len(); + let (from, to) = (Pos2::new(x(120.0), y), Pos2::new(x(156.0), y)); + h.hover_at(from); + h.run_steps(1); + h.drag_at(from); + h.run_steps(1); + // One frame: the pointer moves and lets go (the harness's queued events take a frame each, + // so both go straight into the next frame's input). + let events = &mut h.input_mut().events; + events.push(egui::Event::PointerMoved(to)); + events.push(egui::Event::PointerButton { pos: to, button: egui::PointerButton::Primary, pressed: false, modifiers: egui::Modifiers::NONE }); + h.run_steps(3); + let b = match layer(&h).1 { + Adjustment::HueSaturation { ranges, .. } => ranges[2].bounds, + other => panic!("{other:?}"), + }; + assert!((b[0] - 111.0).abs() <= 1.0 && (b[3] - 201.0).abs() <= 1.0, "all four moved ~36°: {b:?}"); + assert_eq!(h.state().session.active().unwrap().history.past_len(), steps + 1, "one step"); + // A handle released in the frame it moves lands there too. + let (from, to) = (Pos2::new(x(b[3]), y), Pos2::new(x(b[3] + 20.0), y)); + h.hover_at(from); + h.run_steps(1); + h.drag_at(from); + h.run_steps(1); + let events = &mut h.input_mut().events; + events.push(egui::Event::PointerMoved(to)); + events.push(egui::Event::PointerButton { pos: to, button: egui::PointerButton::Primary, pressed: false, modifiers: egui::Modifiers::NONE }); + h.run_steps(3); + let after = match layer(&h).1 { + Adjustment::HueSaturation { ranges, .. } => ranges[2].bounds, + other => panic!("{other:?}"), + }; + assert!((after[3] - (b[3] + 20.0)).abs() <= 1.0 && after[..3] == b[..3], "the right handle moved 20°: {b:?} → {after:?}"); +}