From 943e3618fcdf7f96d3f5f163ad741d96dbe7dbbf Mon Sep 17 00:00:00 2001 From: Hank Jordan Date: Sun, 30 Mar 2025 08:03:19 -0400 Subject: [PATCH] Improve drag-to-select text (add margins) (#5797) Might want to draw from `interaction.interact_radius` style instead of hard-coding the margin, but I didn't want to create a breaking change. If desired, I can follow up with a separate PR to address that concern. * Closes * [x] I have followed the instructions in the PR template --- crates/epaint/src/text/text_layout_types.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/epaint/src/text/text_layout_types.rs b/crates/epaint/src/text/text_layout_types.rs index 6d69045a..b6d7ccf4 100644 --- a/crates/epaint/src/text/text_layout_types.rs +++ b/crates/epaint/src/text/text_layout_types.rs @@ -796,13 +796,16 @@ impl Galley { /// same as a cursor at the end. /// This allows implementing text-selection by dragging above/below the galley. pub fn cursor_from_pos(&self, pos: Vec2) -> CCursor { + // Vertical margin around galley improves text selection UX + const VMARGIN: f32 = 5.0; + if let Some(first_row) = self.rows.first() { - if pos.y < first_row.min_y() { + if pos.y < first_row.min_y() - VMARGIN { return self.begin(); } } if let Some(last_row) = self.rows.last() { - if last_row.max_y() < pos.y { + if last_row.max_y() + VMARGIN < pos.y { return self.end(); } }