Skip to content

Commit 943e361

Browse files
authored
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 <#5796> * [x] I have followed the instructions in the PR template
1 parent ab0f0b7 commit 943e361

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

crates/epaint/src/text/text_layout_types.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -796,13 +796,16 @@ impl Galley {
796796
/// same as a cursor at the end.
797797
/// This allows implementing text-selection by dragging above/below the galley.
798798
pub fn cursor_from_pos(&self, pos: Vec2) -> CCursor {
799+
// Vertical margin around galley improves text selection UX
800+
const VMARGIN: f32 = 5.0;
801+
799802
if let Some(first_row) = self.rows.first() {
800-
if pos.y < first_row.min_y() {
803+
if pos.y < first_row.min_y() - VMARGIN {
801804
return self.begin();
802805
}
803806
}
804807
if let Some(last_row) = self.rows.last() {
805-
if last_row.max_y() < pos.y {
808+
if last_row.max_y() + VMARGIN < pos.y {
806809
return self.end();
807810
}
808811
}

0 commit comments

Comments
 (0)