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
This commit is contained in:
Hojjat 2022-12-17 14:24:22 -07:00 • committed by Jeremy Soller
parent 3ef56b7112
commit 25a3367ef9

View file

@ -378,6 +378,7 @@ impl ShapeSpan {
break; break;
} else if c.is_whitespace() { } else if c.is_whitespace() {
start_lb = start_word + i; start_lb = start_word + i;
break;
} }
} }
if start_word < start_lb { if start_word < start_lb {
@ -391,15 +392,18 @@ impl ShapeSpan {
)); ));
} }
if start_lb < end_lb { if start_lb < end_lb {
for (i, c) in span[start_lb..end_lb].char_indices() {
// assert!(c.is_whitespace());
words.push(ShapeWord::new( words.push(ShapeWord::new(
font_system, font_system,
line, line,
attrs_list, attrs_list,
(span_range.start + start_lb)..(span_range.start + end_lb), (span_range.start + start_lb + i)..(span_range.start + start_lb + i + c.len_utf8()),
level, level,
true, true,
)); ));
} }
}
start_word = end_lb; start_word = end_lb;
} }