From f4637d40c35e068fd60d17c9a42b9114667c9861 Mon Sep 17 00:00:00 2001 From: Levi Zim Date: Sun, 28 Apr 2024 16:58:28 +0800 Subject: [PATCH] fix(reflow): allow wrapping at zero width whitespace (#1074) --- src/widgets/reflow.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/widgets/reflow.rs b/src/widgets/reflow.rs index a175022a66..99c8317a18 100644 --- a/src/widgets/reflow.rs +++ b/src/widgets/reflow.rs @@ -6,6 +6,7 @@ use unicode_width::UnicodeWidthStr; use crate::{layout::Alignment, text::StyledGrapheme}; const NBSP: &str = "\u{00a0}"; +const ZWSP: &str = "\u{200b}"; /// A state machine to pack styled symbols into lines. /// Cannot implement it as Iterator since it yields slices of the internal buffer (need streaming @@ -104,8 +105,8 @@ where let mut has_seen_non_whitespace = false; for StyledGrapheme { symbol, style } in line_symbols { - let symbol_whitespace = - symbol.chars().all(&char::is_whitespace) && symbol != NBSP; + let symbol_whitespace = symbol == ZWSP + || (symbol.chars().all(&char::is_whitespace) && symbol != NBSP); let symbol_width = symbol.width() as u16; // Ignore characters wider than the total max width if symbol_width > self.max_line_width { @@ -706,4 +707,12 @@ mod test { vec![Alignment::Left, Alignment::Right, Alignment::Center] ); } + + #[test] + fn line_composer_zero_width_white_space() { + let width = 3; + let line = "foo\u{200b}bar"; + let (word_wrapper, _, _) = run_composer(Composer::WordWrapper { trim: true }, line, width); + assert_eq!(word_wrapper, vec!["foo", "bar"]); + } }