From 5bfcb2249d8538ca6c907b233a280497a6a5f11c Mon Sep 17 00:00:00 2001 From: bflatastic Date: Mon, 23 Nov 2026 04:28:57 +0700 Subject: [PATCH] ui-contract: a press of any button runs on the click run, as the old apps counted clicks; only a primary press carries the count --- crates/ui-contract/src/runtime/pointer.rs | 13 ++++++--- .../ui-contract/tests/it/runtime/pointer.rs | 27 +++++++++++++++++++ 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/crates/ui-contract/src/runtime/pointer.rs b/crates/ui-contract/src/runtime/pointer.rs index 5bbc7184f..8022e2964 100644 --- a/crates/ui-contract/src/runtime/pointer.rs +++ b/crates/ui-contract/src/runtime/pointer.rs @@ -100,7 +100,7 @@ pub struct PassPointer { #[derive(Default)] pub(crate) struct Memory { - /// The latest primary press: where, when, its click count and the modifiers held with it. + /// The latest press of any button: where, when, its place in the click run and the modifiers held with it. last_press: Option<(Pos2, f64, u32, Mods)>, press_targets: PressTargets, /// A cancel a service requested for the running pass. @@ -260,10 +260,15 @@ pub(crate) fn begin(ctx: &Context, hit: HitSizes, latched: craft_keymap::Mods) { read.events.iter().any(|event| matches!(event, PointerEvent::Pressed { button: PointerButton::Middle | PointerButton::Secondary, .. })); let (events, targets, touched) = PerViewport::::with(ctx, viewport, |memory| { let mut events = read.events.clone(); + // Every button's press runs on the click run, as a click of any button did in the old apps: a middle-button pan + // click between two clicks makes the second a triple click. Only a primary press carries its count. for event in &mut events { - if let PointerEvent::Pressed { button: PointerButton::Primary, pos, time, clicks, .. } = event { - *clicks = count_clicks(memory.last_press, *pos, *time, mods, hit.slop); - memory.last_press = Some((*pos, *time, *clicks, mods)); + if let PointerEvent::Pressed { button, pos, time, clicks, .. } = event { + let counted = count_clicks(memory.last_press, *pos, *time, mods, hit.slop); + memory.last_press = Some((*pos, *time, counted, mods)); + if *button == PointerButton::Primary { + *clicks = counted; + } } } if read.primary_pressed || other_pressed { diff --git a/crates/ui-contract/tests/it/runtime/pointer.rs b/crates/ui-contract/tests/it/runtime/pointer.rs index 802c4fc44..4cbe141b4 100644 --- a/crates/ui-contract/tests/it/runtime/pointer.rs +++ b/crates/ui-contract/tests/it/runtime/pointer.rs @@ -573,3 +573,30 @@ fn a_click_carries_the_modifiers_its_release_carried() { assert_eq!(pick, released, "Shift is the pick's in the release pass only: {seen:?}"); } } + +/// A press of another button counts in the click run as a primary one does: a primary click, a middle click (a pan the +/// view tools take) and a primary click make the last a triple click, as the old apps counted them. Only primary +/// presses carry the count. +#[trial] +fn a_middle_click_between_primary_clicks_counts_in_the_click_run() { + let at = Pos2::new(50.0, 50.0); + let counts: Rc>> = Rc::default(); + let sink = counts.clone(); + let mut show = move |ui: &mut Ui| { + if let Some(press) = craft_ui::runtime::pointer::frame(ui.ctx()).press.filter(|press| press.button == craft_behavior::PointerButton::Primary) + { + sink.borrow_mut().push(press.clicks); + } + }; + let mut frames = Frames::new(); + frames.idle(2, &mut show); + frames.frame(vec![pointer::moved(at)], &mut show); + for button in ["primary", "middle", "primary"] { + let (down, up) = + if button == "middle" { (pointer::middle(at, true), pointer::middle(at, false)) } else { (pointer::press(at), pointer::release(at)) }; + frames.frame(vec![down], &mut show); + frames.frame(vec![up], &mut show); + } + let counts = counts.borrow(); + assert!(counts.len() == 2 && counts[1] == counts[0] + 2, "the middle press counts in the run: {counts:?}"); +}