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:
parent
ceb6dccb40
commit
de587b3f50
1 changed files with 63 additions and 60 deletions
19
src/shape.rs
19
src/shape.rs
|
|
@ -1046,12 +1046,8 @@ impl ShapeLine {
|
|||
} else {
|
||||
// Wrap::Word, Wrap::WordOrGlyph
|
||||
|
||||
// TODO: What if the previous span ended with whitespace and the next
|
||||
// span wraps a new line? Is that possible?
|
||||
//
|
||||
// TODO: This comment it outdated, the current word can be a
|
||||
// whitespace.
|
||||
//
|
||||
// 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
|
||||
// previous word if it's a whitespace
|
||||
let trailing_blank = span
|
||||
|
|
@ -1078,10 +1074,12 @@ impl ShapeLine {
|
|||
number_of_blanks,
|
||||
);
|
||||
}
|
||||
|
||||
visual_lines.push(current_visual_line);
|
||||
current_visual_line = VisualLine::default();
|
||||
|
||||
number_of_blanks = 0;
|
||||
}
|
||||
|
||||
if word.blank {
|
||||
word_range_width = 0.;
|
||||
fitting_start = (i, 0);
|
||||
|
|
@ -1172,9 +1170,12 @@ impl ShapeLine {
|
|||
} else {
|
||||
// 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
|
||||
// previous word if it's a whitespace
|
||||
// previous word if it's a whitespace.
|
||||
let trailing_blank = i > 0 && span.words[i - 1].blank;
|
||||
|
||||
if trailing_blank {
|
||||
number_of_blanks = number_of_blanks.saturating_sub(1);
|
||||
add_to_visual_line(
|
||||
|
|
@ -1195,9 +1196,11 @@ impl ShapeLine {
|
|||
number_of_blanks,
|
||||
);
|
||||
}
|
||||
|
||||
visual_lines.push(current_visual_line);
|
||||
current_visual_line = VisualLine::default();
|
||||
number_of_blanks = 0;
|
||||
}
|
||||
|
||||
if word.blank {
|
||||
word_range_width = 0.;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue