diff --git a/src/widgets/reflow.rs b/src/widgets/reflow.rs index e5f8e2a..94ff733 100644 --- a/src/widgets/reflow.rs +++ b/src/widgets/reflow.rs @@ -57,7 +57,7 @@ impl<'a, 'b> LineComposer<'a> for WordWrapper<'a, 'b> { let mut symbols_exhausted = true; for StyledGrapheme { symbol, style } in &mut self.symbols { symbols_exhausted = false; - let symbol_whitespace = symbol.chars().all(&char::is_whitespace); + let symbol_whitespace = symbol.chars().all(&char::is_whitespace) && symbol != NBSP; // Ignore characters wider that the total max width. if symbol.width() as u16 > self.max_line_width @@ -77,7 +77,7 @@ impl<'a, 'b> LineComposer<'a> for WordWrapper<'a, 'b> { } // Mark the previous symbol as word end. - if symbol_whitespace && !prev_whitespace && symbol != NBSP { + if symbol_whitespace && !prev_whitespace { symbols_to_last_word_end = self.current_line.len(); width_to_last_word_end = current_line_width; } diff --git a/tests/widgets_paragraph.rs b/tests/widgets_paragraph.rs index 9c556eb..a4cd465 100644 --- a/tests/widgets_paragraph.rs +++ b/tests/widgets_paragraph.rs @@ -2,7 +2,7 @@ use tui::{ backend::TestBackend, buffer::Buffer, layout::Alignment, - text::{Spans, Text}, + text::{Span, Spans, Text}, widgets::{Block, Borders, Paragraph, Wrap}, Terminal, }; @@ -141,6 +141,27 @@ fn widgets_paragraph_renders_mixed_width_graphemes() { terminal.backend().assert_buffer(&expected); } +#[test] +fn widgets_paragraph_can_wrap_with_a_trailing_nbsp() { + let nbsp: &str = "\u{00a0}"; + let line = Spans::from(vec![Span::raw("NBSP"), Span::raw(nbsp)]); + let backend = TestBackend::new(20, 3); + let mut terminal = Terminal::new(backend).unwrap(); + let expected = Buffer::with_lines(vec![ + "┌──────────────────┐", + "│NBSP\u{00a0} │", + "└──────────────────┘", + ]); + terminal + .draw(|f| { + let size = f.size(); + + let paragraph = Paragraph::new(line).block(Block::default().borders(Borders::ALL)); + f.render_widget(paragraph, size); + }) + .unwrap(); + terminal.backend().assert_buffer(&expected); +} #[test] fn widgets_paragraph_can_scroll_horizontally() { let test_case = |alignment, scroll, expected| {