From 25a3367ef971dfa077d76c99ac688a12f4449d64 Mon Sep 17 00:00:00 2001 From: Hojjat Date: Sat, 17 Dec 2022 14:24:22 -0700 Subject: [PATCH] Turn a consequtive whitespaces into separate words Currently a sequence like this "hello " (a word followed by 6 spaces). Would be shaped into two words: ["hello " , " "] This causes issues, since the first word is only 5 letters long, not 10 This commit will break this sequence into: ["hello", " ", " ", " ", " ", " ", " "] This helps with correct line wrappipng --- src/shape.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/shape.rs b/src/shape.rs index 55176a9..f82e8fe 100644 --- a/src/shape.rs +++ b/src/shape.rs @@ -378,6 +378,7 @@ impl ShapeSpan { break; } else if c.is_whitespace() { start_lb = start_word + i; + break; } } if start_word < start_lb { @@ -391,14 +392,17 @@ impl ShapeSpan { )); } if start_lb < end_lb { - words.push(ShapeWord::new( - font_system, - line, - attrs_list, - (span_range.start + start_lb)..(span_range.start + end_lb), - level, - true, - )); + for (i, c) in span[start_lb..end_lb].char_indices() { + // assert!(c.is_whitespace()); + words.push(ShapeWord::new( + font_system, + line, + attrs_list, + (span_range.start + start_lb + i)..(span_range.start + start_lb + i + c.len_utf8()), + level, + true, + )); + } } start_word = end_lb; }