From 72f282eb3ade6077c5f697c131915787b2c0ff45 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 25 Aug 2021 15:21:04 +0200 Subject: [PATCH] Calculate current line width correctly when wrapping shaped lines --- gpui/src/text_layout.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/gpui/src/text_layout.rs b/gpui/src/text_layout.rs index 9d171e180c..8591dbe7f2 100644 --- a/gpui/src/text_layout.rs +++ b/gpui/src/text_layout.rs @@ -458,7 +458,8 @@ impl LineWrapper { glyph.position.x(), ) }) - }); + }) + .peekable(); iter::from_fn(move || { while let Some((ix, c, x)) = glyphs.next() { @@ -475,7 +476,8 @@ impl LineWrapper { first_non_whitespace_ix = Some(ix); } - let width = x - last_wrap_x; + let next_x = glyphs.peek().map_or(line.width(), |(_, _, x)| *x); + let width = next_x - last_wrap_x; if width > wrap_width && ix > last_wrap_ix { if let Some(last_candidate_ix) = last_candidate_ix.take() { last_wrap_ix = last_candidate_ix; @@ -623,7 +625,7 @@ mod tests { } #[crate::test(self)] - fn test_wrap_layout_line(cx: &mut crate::MutableAppContext) { + fn test_wrap_shaped_line(cx: &mut crate::MutableAppContext) { let font_cache = cx.font_cache().clone(); let font_system = cx.platform().fonts(); let text_layout_cache = TextLayoutCache::new(font_system.clone());