diff options
author | Quentin | 2024-03-25 01:29:36 +0000 |
---|---|---|
committer | GitHub | 2024-03-25 01:29:36 +0000 |
commit | 614a744d24e54225eae2ad0d27719b81c0cf9a4d (patch) | |
tree | d7d70ed5ffa7d883ddc6c9d2ac96ac5c8e4fa1dc /helix-tui/src/widgets | |
parent | 2d9e336f640cccdd347e35289c3e4c0371777a3f (diff) |
Add narrow no-break space support (#9604)
Diffstat (limited to 'helix-tui/src/widgets')
-rw-r--r-- | helix-tui/src/widgets/reflow.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/helix-tui/src/widgets/reflow.rs b/helix-tui/src/widgets/reflow.rs index c30aa6e0..67c4db44 100644 --- a/helix-tui/src/widgets/reflow.rs +++ b/helix-tui/src/widgets/reflow.rs @@ -4,6 +4,7 @@ use helix_core::unicode::width::UnicodeWidthStr; use unicode_segmentation::UnicodeSegmentation; const NBSP: &str = "\u{00a0}"; +const NNBSP: &str = "\u{202f}"; /// A state machine to pack styled symbols into lines. /// Cannot implement it as Iterator since it yields slices of the internal buffer (need streaming @@ -58,7 +59,8 @@ 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) && symbol != NBSP; + let symbol_whitespace = + symbol.chars().all(&char::is_whitespace) && symbol != NBSP && symbol != NNBSP; // Ignore characters wider that the total max width. if symbol.width() as u16 > self.max_line_width @@ -497,6 +499,20 @@ mod test { } #[test] + fn line_composer_word_wrapper_nnbsp() { + let width = 20; + let text = "AAAAAAAAAAAAAAA AAAA\u{202f}AAA"; + let (word_wrapper, _) = run_composer(Composer::WordWrapper { trim: true }, text, width); + assert_eq!(word_wrapper, vec!["AAAAAAAAAAAAAAA", "AAAA\u{202f}AAA",]); + + // Ensure that if the character was a regular space, it would be wrapped differently. + let text_space = text.replace('\u{202f}', " "); + let (word_wrapper_space, _) = + run_composer(Composer::WordWrapper { trim: true }, &text_space, width); + assert_eq!(word_wrapper_space, vec!["AAAAAAAAAAAAAAA AAAA", "AAA",]); + } + + #[test] fn line_composer_word_wrapper_preserve_indentation() { let width = 20; let text = "AAAAAAAAAAAAAAAAAAAA AAA"; |