From 0b8ec5372ba5679f02935c037bffbe623869a825 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Tue, 14 Nov 2023 17:06:18 +0100 Subject: [PATCH] Return the line length when `x` is past the last glyph Co-Authored-By: Julia --- crates/gpui2/src/text_system/line_layout.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/gpui2/src/text_system/line_layout.rs b/crates/gpui2/src/text_system/line_layout.rs index db7140b04076c1fdf705ef9526ba54f691c7d81f..7e9176cacaeedf61234a42bb02bd48fd2eae398f 100644 --- a/crates/gpui2/src/text_system/line_layout.rs +++ b/crates/gpui2/src/text_system/line_layout.rs @@ -54,9 +54,9 @@ impl LineLayout { pub fn closest_index_for_x(&self, x: Pixels) -> usize { let mut prev_index = 0; let mut prev_x = px(0.); + for run in self.runs.iter() { for glyph in run.glyphs.iter() { - glyph.index; if glyph.position.x >= x { if glyph.position.x - x < x - prev_x { return glyph.index; @@ -68,7 +68,8 @@ impl LineLayout { prev_x = glyph.position.x; } } - prev_index + 1 + + self.len } pub fn x_for_index(&self, index: usize) -> Pixels {