stop inserting a new line in the sentence

pull/84/head
Takayuki Maeda 3 years ago
parent 25cb17e7e1
commit 4561c5c5f1

@ -86,28 +86,7 @@ impl<'a, 'b> LineComposer<'a> for WordWrapper<'a, 'b> {
self.current_line.push(StyledGrapheme { symbol, style });
current_line_width += Cast::<u16>::cast(symbol.width());
if current_line_width > self.max_line_width {
// If there was no word break in the text, wrap at the end of the line.
let (truncate_at, truncated_width) = if symbols_to_last_word_end == 0 {
(self.current_line.len() - 1, self.max_line_width)
} else {
(symbols_to_last_word_end, width_to_last_word_end)
};
// Push the remainder to the next line but strip leading whitespace:
{
let remainder = &self.current_line[truncate_at..];
if let Some(remainder_nonwhite) =
remainder.iter().position(|StyledGrapheme { symbol, .. }| {
!symbol.chars().all(&char::is_whitespace)
})
{
self.next_line
.extend_from_slice(&remainder[remainder_nonwhite..]);
}
}
self.current_line.truncate(truncate_at);
current_line_width = truncated_width;
if current_line_width >= self.max_line_width {
break;
}

Loading…
Cancel
Save