Only commit a previous word range if we had an existing visual line.

Fixes #155, and also fixes Word::Wrap when two buffer overflowing words are next to each other.
This commit is contained in:
dtzxporter 2024-02-02 13:29:53 -05:00 • committed by Jeremy Soller
parent ceb6dccb40
commit de587b3f50

View file

@ -1046,12 +1046,8 @@ impl ShapeLine {
} else { } else {
// Wrap::Word, Wrap::WordOrGlyph // Wrap::Word, Wrap::WordOrGlyph
// TODO: What if the previous span ended with whitespace and the next // If we had a previous range, commit that line before the next word.
// span wraps a new line? Is that possible? if word_range_width > 0. {
//
// TODO: This comment it outdated, the current word can be a
// whitespace.
//
// Current word causing a wrap is not whitespace, so we ignore the // Current word causing a wrap is not whitespace, so we ignore the
// previous word if it's a whitespace // previous word if it's a whitespace
let trailing_blank = span let trailing_blank = span
@ -1078,10 +1074,12 @@ impl ShapeLine {
number_of_blanks, number_of_blanks,
); );
} }
visual_lines.push(current_visual_line); visual_lines.push(current_visual_line);
current_visual_line = VisualLine::default(); current_visual_line = VisualLine::default();
number_of_blanks = 0; number_of_blanks = 0;
}
if word.blank { if word.blank {
word_range_width = 0.; word_range_width = 0.;
fitting_start = (i, 0); fitting_start = (i, 0);
@ -1172,9 +1170,12 @@ impl ShapeLine {
} else { } else {
// Wrap::Word, Wrap::WordOrGlyph // Wrap::Word, Wrap::WordOrGlyph
// If we had a previous range, commit that line before the next word.
if word_range_width > 0. {
// Current word causing a wrap is not whitespace, so we ignore the // Current word causing a wrap is not whitespace, so we ignore the
// previous word if it's a whitespace // previous word if it's a whitespace.
let trailing_blank = i > 0 && span.words[i - 1].blank; let trailing_blank = i > 0 && span.words[i - 1].blank;
if trailing_blank { if trailing_blank {
number_of_blanks = number_of_blanks.saturating_sub(1); number_of_blanks = number_of_blanks.saturating_sub(1);
add_to_visual_line( add_to_visual_line(
@ -1195,9 +1196,11 @@ impl ShapeLine {
number_of_blanks, number_of_blanks,
); );
} }
visual_lines.push(current_visual_line); visual_lines.push(current_visual_line);
current_visual_line = VisualLine::default(); current_visual_line = VisualLine::default();
number_of_blanks = 0; number_of_blanks = 0;
}
if word.blank { if word.blank {
word_range_width = 0.; word_range_width = 0.;