From 5c13c843f9ab9fe7fefc891848cf387fb847fd00 Mon Sep 17 00:00:00 2001 From: Juan Campa Date: Wed, 17 Apr 2024 18:57:00 -0400 Subject: [PATCH] Fix incorrect line breaks --- crates/epaint/src/text/text_layout.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/crates/epaint/src/text/text_layout.rs b/crates/epaint/src/text/text_layout.rs index 322026da3c5..57241bfbcbf 100644 --- a/crates/epaint/src/text/text_layout.rs +++ b/crates/epaint/src/text/text_layout.rs @@ -296,7 +296,7 @@ fn line_break(paragraph: &Paragraph, job: &LayoutJob, out_rows: &mut Vec, e // Start a new row: row_start_idx = last_kept_index + 1; row_start_x = paragraph.glyphs[row_start_idx].pos.x; - row_break_candidates = Default::default(); + row_break_candidates.forget_candiates_before_idx(row_start_idx); } else { // Found no place to break, so we have to overrun wrap_width. } @@ -943,6 +943,27 @@ impl RowBreakCandidates { .or(self.any) } } + + fn forget_candiates_before_idx(&mut self, index: usize) { + if self.space.map(|s| s < index).unwrap_or_default() { + self.space = None; + } + if self.cjk.map(|s| s < index).unwrap_or_default() { + self.cjk = None; + } + if self.pre_cjk.map(|s| s < index).unwrap_or_default() { + self.pre_cjk = None; + } + if self.dash.map(|s| s < index).unwrap_or_default() { + self.dash = None; + } + if self.punctuation.map(|s| s < index).unwrap_or_default() { + self.punctuation = None; + } + if self.any.map(|s| s < index).unwrap_or_default() { + self.any = None; + } + } } #[inline]