mirror of
https://github.com/ratatui/ratatui.git
synced 2025-10-02 07:21:24 +00:00
fix(widgets/paragraph): handle trailing nbsp in wrapped text (#405)
This commit is contained in:
parent
1e35f983c4
commit
5bf40343eb
@ -57,7 +57,7 @@ impl<'a, 'b> LineComposer<'a> for WordWrapper<'a, 'b> {
|
|||||||
let mut symbols_exhausted = true;
|
let mut symbols_exhausted = true;
|
||||||
for StyledGrapheme { symbol, style } in &mut self.symbols {
|
for StyledGrapheme { symbol, style } in &mut self.symbols {
|
||||||
symbols_exhausted = false;
|
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.
|
// Ignore characters wider that the total max width.
|
||||||
if symbol.width() as u16 > self.max_line_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.
|
// 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();
|
symbols_to_last_word_end = self.current_line.len();
|
||||||
width_to_last_word_end = current_line_width;
|
width_to_last_word_end = current_line_width;
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ use tui::{
|
|||||||
backend::TestBackend,
|
backend::TestBackend,
|
||||||
buffer::Buffer,
|
buffer::Buffer,
|
||||||
layout::Alignment,
|
layout::Alignment,
|
||||||
text::{Spans, Text},
|
text::{Span, Spans, Text},
|
||||||
widgets::{Block, Borders, Paragraph, Wrap},
|
widgets::{Block, Borders, Paragraph, Wrap},
|
||||||
Terminal,
|
Terminal,
|
||||||
};
|
};
|
||||||
@ -141,6 +141,27 @@ fn widgets_paragraph_renders_mixed_width_graphemes() {
|
|||||||
terminal.backend().assert_buffer(&expected);
|
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]
|
#[test]
|
||||||
fn widgets_paragraph_can_scroll_horizontally() {
|
fn widgets_paragraph_can_scroll_horizontally() {
|
||||||
let test_case = |alignment, scroll, expected| {
|
let test_case = |alignment, scroll, expected| {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user