From 565912d7353f55d5b6236114eb30cfb85f9cb479 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 3 Dec 2026 11:36:11 -0800 Subject: [PATCH] Fix #10560: the stop popover stays open when a double click on a stop drifts A double click on a stop's marker in the Gradient panel's slider opens the stop popover on its second press. The slider also treated that press as a drag once the pointer moved past the drag threshold before the release, which a hand on a trackpad often does. The stop moved a few percent, an undo step was recorded, and the popover closed in the next frame because its stop had changed under it. The panel now drops the slider's edits from the press that opened the popover, including the commit that arrives after the button is up. The next press drags the stop as before. craft-libs#5131 fixes the slider itself; this code goes away with the pin bump that brings it in. --- crates/ui-egui/src/panels/gradient.rs | 22 +++++++++++ .../tests/gradient_stop_color_mode_menu.rs | 38 +++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/crates/ui-egui/src/panels/gradient.rs b/crates/ui-egui/src/panels/gradient.rs index 4c8122fa77..9d6088cbd3 100644 --- a/crates/ui-egui/src/panels/gradient.rs +++ b/crates/ui-egui/src/panels/gradient.rs @@ -102,6 +102,13 @@ pub struct GradientUi { /// `paint.editGradient` sorts the stops, so the gradient shown mid-gesture is the last preview /// re-sorted: the editor's tags name stops of this one. pub(crate) begun: Option>, + /// The press of a double click that asked for a stop's color is still held. Until craft-libs#5131 reaches the + /// pin, the slider also drags the stop when the pointer drifts during that press, and the moved stop closes the + /// popover the double click opened: the panel drops that press's slider edits. + pub(crate) color_press: bool, + /// The slider's gesture that the press above began, dropped until its `Commit` or `Cancel`, which can arrive in a + /// pass after the button is up. + pub(crate) color_drag: bool, } /// Select stop `i` (the session's selected stop, shared with the Gradient tool's annotator, the @@ -829,6 +836,21 @@ fn stops_editor(app: &mut VectorcraftApp, ui: &mut Ui, g: &GradientPaint, is_gra .shared_selection(Bind::bound(&mut shared)) .drop_target::() .show(ui); + let panel = &mut app.ui.gradient_panel; + let color_press = panel.color_press || out.color_requested.is_some(); + let held = craft::ui::runtime::pointer::press_state(ui.ctx()).buttons.contains(craft::behavior::Buttons::PRIMARY); + let dropping = panel.color_drag || (color_press && out.edit.events.began()); + let ended = matches!(out.edit.events.last(), Some(EditEvent::Commit { .. } | EditEvent::Cancel { .. } | EditEvent::Set { .. })); + panel.color_press = color_press && held; + panel.color_drag = dropping && !ended; + if color_press || dropping { + // The drift of the press that asked for the color moves no stop (craft-libs#5131). + if is_grad && let Some(request) = &out.color_requested { + let at = request.rect.map_or(out.edit.response.rect.left_bottom(), |r| r.left_bottom()); + open_popover(app, request.index, at); + } + return; + } let events = &out.edit.events; if !is_grad { // The slider shows the default gradient: an edit of it applies a gradient first. diff --git a/crates/ui-egui/tests/gradient_stop_color_mode_menu.rs b/crates/ui-egui/tests/gradient_stop_color_mode_menu.rs index 48a722c7a7..66b62550d3 100644 --- a/crates/ui-egui/tests/gradient_stop_color_mode_menu.rs +++ b/crates/ui-egui/tests/gradient_stop_color_mode_menu.rs @@ -267,6 +267,44 @@ impl Scene { } } +/// The pointer drifting a few points while the second press of a double click on a stop's marker is held leaves the +/// stop where it was, so the popover the double click opened stays open (#10560). +#[test] +fn gradient_stop_popover_stays_open_when_the_double_click_drifts() { + let _globals = GlobalState::new(); + let mut scene = Scene::new(vec2(960.0, 720.0), false); + scene.idle(8); + let marker = scene.nodes.iter().filter(|n| n.label() == Some("Color stop 1 of 2")).find_map(Scene::node_rect).expect("the stop's marker"); + let before = scene.snapshot(); + let at = marker.center(); + let button = |pos: Pos2, pressed: bool| Event::PointerButton { pos, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE }; + scene.frame(vec![Event::PointerMoved(at)]); + for pressed in [true, false, true] { + scene.frame(vec![button(at, pressed)]); + } + assert!(scene.editor_open(), "the second press opens the popover"); + let mut to = at; + for step in 1..=6 { + to = at + vec2(step as f32, 0.0); + scene.frame(vec![Event::PointerMoved(to)]); + } + scene.frame(vec![button(to, false)]); + scene.idle(3); + assert!(scene.editor_open(), "the popover stays open after the drift and the release"); + assert_eq!(scene.snapshot(), before, "the drift moves no stop and records no undo step"); + // A drag of its own, after the double click's time, moves the stop again. + scene.escape(); + scene.idle(30); + scene.frame(vec![Event::PointerMoved(at)]); + scene.frame(vec![button(at, true)]); + for step in 1..=4 { + scene.frame(vec![Event::PointerMoved(at + vec2(15.0 * step as f32, 0.0))]); + } + scene.frame(vec![button(at + vec2(60.0, 0.0), false)]); + scene.idle(3); + assert!(scene.gradient().gradient.stops[0].offset > 0.0, "the next drag moves the stop"); +} + #[test] fn gradient_stop_mode_baseline_shift_and_menu_are_display_only() { let _globals = GlobalState::new();