Fix indices (suggestions by geieredgar)

This commit is contained in:
Hojjat 2023-03-13 13:08:35 -06:00
parent 01e609f3d6
commit 05b069911a

View file

@ -721,15 +721,13 @@ impl ShapeLine {
} else { } else {
// Wrap::Word // Wrap::Word
let mut trailing_space_width = None; let mut trailing_space_width = None;
if i > 0 { if let Some(previous_word) = span.words.get(i + 1) {
if let Some(previous_word) = span.words.get(i - 1) { // 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 if previous_word.blank {
if previous_word.blank { trailing_space_width =
trailing_space_width = Some(previous_word.x_advance * font_size);
Some(previous_word.x_advance * font_size); number_of_blanks = number_of_blanks.saturating_sub(1);
number_of_blanks = number_of_blanks.saturating_sub(1);
}
} }
} }
if let Some(width) = trailing_space_width { if let Some(width) = trailing_space_width {
@ -758,7 +756,7 @@ impl ShapeLine {
if word.blank { if word.blank {
fit_x = line_width; fit_x = line_width;
word_range_width = 0.; word_range_width = 0.;
fitting_start = (i + 1, 0); fitting_start = (i, 0);
} else { } else {
fit_x = line_width - word_width; fit_x = line_width - word_width;
word_range_width = word_width; word_range_width = word_width;
@ -815,10 +813,7 @@ impl ShapeLine {
} else { } else {
// Wrap::Word // Wrap::Word
let mut trailing_space_width = None; let mut trailing_space_width = None;
if word.blank { if i > 0 {
// current word causing a wrap is a space so we ignore it
// number_of_blanks = number_of_blanks.saturating_sub(1);
} else if i > 0 {
if let Some(previous_word) = span.words.get(i - 1) { if let Some(previous_word) = span.words.get(i - 1) {
// 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
@ -834,7 +829,7 @@ impl ShapeLine {
&mut current_visual_line, &mut current_visual_line,
span_index, span_index,
fitting_start, fitting_start,
(i, 0), (i - 1, 0),
word_range_width - width, word_range_width - width,
number_of_blanks, number_of_blanks,
); );