Fix word wrapping with successive forced breaks
If there were multiple forced breaks in succession, all except the first would be a bit too wide since I forgot to include the current grapheme in the new line's width.
This commit is contained in:
parent
dfc10f9d09
commit
d186291ef7
1 changed files with 5 additions and 3 deletions
|
|
@ -52,13 +52,15 @@ pub fn wrap(widthdb: &mut WidthDB, tab_width: u8, text: &str, width: usize) -> V
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate widths after current grapheme
|
// Calculate widths after current grapheme
|
||||||
|
let g_is_whitespace = g.chars().all(|c| c.is_whitespace());
|
||||||
let g_width = if g == "\t" {
|
let g_width = if g == "\t" {
|
||||||
tab_width_at_column(tab_width, current_width) as usize
|
tab_width_at_column(tab_width, current_width) as usize
|
||||||
} else {
|
} else {
|
||||||
widthdb.grapheme_width(g) as usize
|
widthdb.grapheme_width(g) as usize
|
||||||
};
|
};
|
||||||
|
let g_width_trimmed = if g_is_whitespace { 0 } else { g_width };
|
||||||
let mut new_width = current_width + g_width;
|
let mut new_width = current_width + g_width;
|
||||||
let mut new_width_trimmed = if g.chars().all(|c| c.is_whitespace()) {
|
let mut new_width_trimmed = if g_is_whitespace {
|
||||||
current_width_trimmed
|
current_width_trimmed
|
||||||
} else {
|
} else {
|
||||||
new_width
|
new_width
|
||||||
|
|
@ -87,8 +89,8 @@ pub fn wrap(widthdb: &mut WidthDB, tab_width: u8, text: &str, width: usize) -> V
|
||||||
// Forced break in the midde of a normally non-breakable chunk
|
// Forced break in the midde of a normally non-breakable chunk
|
||||||
// because there are no valid break points.
|
// because there are no valid break points.
|
||||||
breaks.push(gi);
|
breaks.push(gi);
|
||||||
new_width = 0;
|
new_width = g_width;
|
||||||
new_width_trimmed = 0;
|
new_width_trimmed = g_width_trimmed;
|
||||||
valid_break = None;
|
valid_break = None;
|
||||||
valid_break_width = 0;
|
valid_break_width = 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue