Fix duplicate visual lines when a word is too long

Words longer than the linewidth used to show up duplicated
This commit is contained in:
Hojjat 2022-12-17 15:38:11 -07:00 committed by Jeremy Soller
parent e38a302599
commit 8beeca2822

View file

@ -660,7 +660,6 @@ impl ShapeLine {
} }
word_ranges.push((fitting_start..fitting_end, true)); word_ranges.push((fitting_start..fitting_end, true));
fitting_end = i + 1; fitting_end = i + 1;
fit_x = start_x; fit_x = start_x;
} }
@ -701,13 +700,16 @@ impl ShapeLine {
}; };
if wrap { if wrap {
word_ranges.push((fitting_start..i, true)); if fitting_start == i { // One word is bigger than the linewidth
if word.blank {
i += 1; i += 1;
} }
word_ranges.push((fitting_start..i, true));
if let Some(next_word) = &span.words.get(i) {
if next_word.blank {
i += 1;
}
}
fitting_start = i; fitting_start = i;
fit_x = start_x; fit_x = start_x;
} }
@ -723,8 +725,10 @@ impl ShapeLine {
} }
} }
} }
if fitting_start < span.words.len() {
word_ranges.push((fitting_start..span.words.len(), false)); word_ranges.push((fitting_start..span.words.len(), false));
} }
}
// Calculate the actual size // Calculate the actual size
for (range, wrap) in word_ranges { for (range, wrap) in word_ranges {
@ -737,7 +741,6 @@ impl ShapeLine {
} else { } else {
x + word_size > end_x x + word_size > end_x
}; };
if word_wrap && !wrap_simple { if word_wrap && !wrap_simple {
current_visual_line.push((span_index, range.clone())); current_visual_line.push((span_index, range.clone()));
vl_range_of_spans.push(current_visual_line); vl_range_of_spans.push(current_visual_line);
@ -769,7 +772,6 @@ impl ShapeLine {
vl_range_of_spans.push(current_visual_line); vl_range_of_spans.push(current_visual_line);
} }
for visual_line in &vl_range_of_spans { for visual_line in &vl_range_of_spans {
let new_order = self.reorder(visual_line); let new_order = self.reorder(visual_line);
let mut glyphs = Vec::with_capacity(1); let mut glyphs = Vec::with_capacity(1);