mirror of
https://github.com/ratatui/ratatui.git
synced 2025-10-02 15:25:54 +00:00
fix: avoid extra line break on whitespace only lines when wrapping paragraphs (#1636)
Currently whitespace only lines produces an extra line break when trimming is disabled, because both the trimmed as well as the non-trimmed line get inserted. Fix this by only inserting the non-trimmed one. Co-authored-by: Björn Steinbrink <b.steinbrink@demv.de>
This commit is contained in:
parent
9f399ac7a6
commit
f5fc8197ff
@ -778,6 +778,34 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_render_wrapped_paragraph_with_whitespace_only_line() {
|
||||||
|
let text: Text = ["A", " ", "B", " a", "C"].into_iter().map(Line::from).collect();
|
||||||
|
let paragraph = Paragraph::new(text.clone()).wrap(Wrap { trim: false });
|
||||||
|
let trimmed_paragraph = Paragraph::new(text).wrap(Wrap { trim: true });
|
||||||
|
|
||||||
|
test_case(
|
||||||
|
¶graph,
|
||||||
|
&Buffer::with_lines([
|
||||||
|
"A",
|
||||||
|
" ",
|
||||||
|
"B",
|
||||||
|
" a",
|
||||||
|
"C",
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
test_case(
|
||||||
|
&trimmed_paragraph,
|
||||||
|
&Buffer::with_lines([
|
||||||
|
"A",
|
||||||
|
"",
|
||||||
|
"B",
|
||||||
|
"a",
|
||||||
|
"C",
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_render_paragraph_with_line_truncation() {
|
fn test_render_paragraph_with_line_truncation() {
|
||||||
let text = "This is a long line of text that should be truncated.";
|
let text = "This is a long line of text that should be truncated.";
|
||||||
|
@ -167,6 +167,7 @@ where
|
|||||||
if pending_line.is_empty()
|
if pending_line.is_empty()
|
||||||
&& self.pending_word.is_empty()
|
&& self.pending_word.is_empty()
|
||||||
&& !self.pending_whitespace.is_empty()
|
&& !self.pending_whitespace.is_empty()
|
||||||
|
&& self.trim
|
||||||
{
|
{
|
||||||
self.wrapped_lines.push_back(vec![]);
|
self.wrapped_lines.push_back(vec![]);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user