From 42f69621a23998e2ebbb0ac76992feab52395bb3 Mon Sep 17 00:00:00 2001 From: yoriswind Date: Wed, 18 Nov 2026 12:12:05 -0800 Subject: [PATCH] Keep a cancelled trace sampler press owned through release --- crates/ui-egui/src/canvas.rs | 19 +++++++++++++++++-- .../tests/image_trace_ignore_sampler.rs | 11 +++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index e401b0a70b..c10ca61fb4 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -466,9 +466,24 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { } } -/// A press arriving with an invalidated sampler is consumed, not given to its restored tool. +/// A press arriving with an invalidated sampler and its release belong to that cancelled pick. fn input_after_sampler_refresh(app: &mut VectorcraftApp, ui: &Ui, resp: &egui::Response, rect: egui::Rect, cancelled: bool) { - if !cancelled || !ui.input(|i| i.pointer.any_pressed()) { + let (pressed, released, down, any_pressed) = ui.input(|i| { + (i.pointer.primary_pressed(), i.pointer.primary_released(), i.pointer.primary_down(), i.pointer.any_pressed()) + }); + let consumed_primary = ui.data_mut(|data| { + let id = resp.id.with("image-trace-consumed-primary"); + // A fresh press replaces any ownership whose release this canvas did not observe. + let consumed = if pressed { cancelled } else { data.get_temp::(id).unwrap_or(false) }; + if consumed && down { + data.insert_temp(id, true); + } else { + data.remove::(id); + } + // egui classifies double/triple clicks on release, independently of the tool's Down. + consumed && (pressed || released || down) + }); + if !consumed_primary && (!cancelled || !any_pressed) { canvas_input(app, ui, resp, rect); } } diff --git a/crates/ui-egui/tests/image_trace_ignore_sampler.rs b/crates/ui-egui/tests/image_trace_ignore_sampler.rs index bc9fd97eb1..5a61946659 100644 --- a/crates/ui-egui/tests/image_trace_ignore_sampler.rs +++ b/crates/ui-egui/tests/image_trace_ignore_sampler.rs @@ -481,6 +481,17 @@ fn a_consumed_stale_sampler_press_does_not_complete_a_double_click() { assert_eq!((state.history.undo.len(), state.history.redo.len()), history); assert_eq!(app.session.paint, paint); assert_eq!(app.session.tool_id(), "selection"); + // The consumed release must not take the next independent ordinary gesture with it. + let next = start + 4.0 * step + delay + 1.0; + frame_at(&mut app, &ctx, next, vec![Event::PointerMoved(at), press(true)]); + frame_at(&mut app, &ctx, next + step, vec![press(false)]); + assert!(!ctx.input(|i| i.pointer.button_double_clicked(PointerButton::Primary))); + assert_eq!(app.session.active().unwrap().selection.objects, vec![group], "the next ordinary first click selects the group"); + assert_eq!(app.session.active().unwrap().isolation, None); + frame_at(&mut app, &ctx, next + 3.0 * step, vec![press(true)]); + frame_at(&mut app, &ctx, next + 4.0 * step, vec![press(false)]); + assert!(ctx.input(|i| i.pointer.button_double_clicked(PointerButton::Primary))); + assert_eq!(app.session.active().unwrap().isolation, Some(group), "the next ordinary double-click still isolates the group"); } else { assert_eq!(app.session.active().unwrap().selection.objects, vec![group], "the ordinary first click really selects the group"); frame_at(&mut app, &ctx, start + 3.0 * step, vec![press(true)]);