diff --git a/ratatui-widgets/src/paragraph.rs b/ratatui-widgets/src/paragraph.rs index d697b76c..b0f049c9 100644 --- a/ratatui-widgets/src/paragraph.rs +++ b/ratatui-widgets/src/paragraph.rs @@ -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] fn test_render_paragraph_with_line_truncation() { let text = "This is a long line of text that should be truncated."; diff --git a/ratatui-widgets/src/reflow.rs b/ratatui-widgets/src/reflow.rs index 4aefa9e0..46a5f8c3 100644 --- a/ratatui-widgets/src/reflow.rs +++ b/ratatui-widgets/src/reflow.rs @@ -167,6 +167,7 @@ where if pending_line.is_empty() && self.pending_word.is_empty() && !self.pending_whitespace.is_empty() + && self.trim { self.wrapped_lines.push_back(vec![]); }