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();