From 2a10d1400e17d0deb5ac608725a45da483bdbc1f Mon Sep 17 00:00:00 2001 From: aiongg Date: Tue, 17 Nov 2026 06:11:29 +0000 Subject: [PATCH] =?UTF-8?q?A=20press=20on=20a=20guide=20keeps=20the=20guid?= =?UTF-8?q?es'=20parts=20declared=20until=20it=20ends:=20a=20=E2=8C=98-pre?= =?UTF-8?q?ss=20whose=20key=20is=20let=20go=20before=20the=20drag=20keeps?= =?UTF-8?q?=20its=20guide=20and=20focus?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/canvas_controls/guides/mod.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/crates/ui-canvas/src/canvas_controls/guides/mod.rs b/crates/ui-canvas/src/canvas_controls/guides/mod.rs index 2d8989a17..36be120da 100644 --- a/crates/ui-canvas/src/canvas_controls/guides/mod.rs +++ b/crates/ui-canvas/src/canvas_controls/guides/mod.rs @@ -115,6 +115,11 @@ const CANVAS_DELETES: [Chord; 2] = [Chord::plain(Key::Delete), Chord::plain(Key: #[derive(Clone, Default)] struct PendingKey(Option); +/// The press slot of a press on a guide: set at the press, cleared when it ends, so the parts a held key declared stay +/// declared until the press ends, though the key is let go before the drag begins. +#[derive(Clone, Copy, Default)] +struct HeldGuide; + /// The ruler guides of a canvas: drawn, taken by the pointer and moved with the keyboard. /// /// - The pointer takes an unlocked guide while the guides are [`interactive`](Guides::interactive), or with the @@ -291,6 +296,11 @@ impl<'a> Guides<'a> { for guide in guides.iter().filter(|guide| !guide.locked) { let Some(result) = cx.part_if_declared(guide.key.part(GUIDE)) else { continue }; let press = result.press; + match press.phase { + PressPhase::Down { .. } => *cx.press_slot::() = Some(HeldGuide), + PressPhase::Release { .. } | PressPhase::Cancel { .. } => *cx.press_slot::() = None, + _ => {} + } match press.phase { PressPhase::Down { start, .. } if start.button == PointerButton::Primary => { self.report.select = Some(Some(guide.key)); @@ -467,11 +477,12 @@ impl Component for Guides<'_> { /// The unlocked guides in view: edge-level drag parts in one roving group, in keyboard order. Page Up and Page /// Down move the group's arrival; the arrows are the guide's nudge. With `interactive` off they are declared only - /// for `moves_with_command`, while the command key is held or the guides' own drag runs, so a guide drag begun - /// with the key keeps its part when the key is let go mid-drag; `run_pointer` reads only declared parts, so this - /// is the one gate of the pointer. + /// for `moves_with_command`, while the command key is held, a press on a guide is down or the guides' own drag + /// runs, so a guide press begun with the key keeps its part when the key is let go before or during the drag; + /// `run_pointer` reads only declared parts, so this is the one gate of the pointer. fn parts(&mut self, rect: egui::Rect, cx: &mut PartsCx<'_, Self>) { - let takes = self.interactive || (self.moves_with_command && (crate::runtime::pointer::frame(cx.ui.ctx()).mods.cmd || cx.gesture_running())); + let held = cx.press_slot::().is_some() || cx.gesture_running(); + let takes = self.interactive || (self.moves_with_command && (crate::runtime::pointer::frame(cx.ui.ctx()).mods.cmd || held)); let (Some(space), Some(guides), true) = (canvas_space(&cx.env), cx.value(), takes) else { return }; let mut any = false; for &at in &place::keyboard_order(guides) {