Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-tui/src/widgets/reflow.rs')
| -rw-r--r-- | helix-tui/src/widgets/reflow.rs | 32 |
1 files changed, 8 insertions, 24 deletions
diff --git a/helix-tui/src/widgets/reflow.rs b/helix-tui/src/widgets/reflow.rs index ff102eb1..21847783 100644 --- a/helix-tui/src/widgets/reflow.rs +++ b/helix-tui/src/widgets/reflow.rs @@ -4,7 +4,6 @@ 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 @@ -39,7 +38,7 @@ impl<'a, 'b> WordWrapper<'a, 'b> { } } -impl<'a> LineComposer<'a> for WordWrapper<'a, '_> { +impl<'a, 'b> LineComposer<'a> for WordWrapper<'a, 'b> { fn next_line(&mut self) -> Option<(&[StyledGrapheme<'a>], u16)> { if self.max_line_width == 0 { return None; @@ -59,8 +58,7 @@ impl<'a> LineComposer<'a> for WordWrapper<'a, '_> { 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 && symbol != NNBSP; + 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 @@ -130,7 +128,7 @@ pub struct LineTruncator<'a, 'b> { symbols: &'b mut dyn Iterator<Item = StyledGrapheme<'a>>, max_line_width: u16, current_line: Vec<StyledGrapheme<'a>>, - /// Record the offset to skip render + /// Record the offet to skip render horizontal_offset: u16, } @@ -152,7 +150,7 @@ impl<'a, 'b> LineTruncator<'a, 'b> { } } -impl<'a> LineComposer<'a> for LineTruncator<'a, '_> { +impl<'a, 'b> LineComposer<'a> for LineTruncator<'a, 'b> { fn next_line(&mut self) -> Option<(&[StyledGrapheme<'a>], u16)> { if self.max_line_width == 0 { return None; @@ -406,8 +404,8 @@ mod test { let text = "コンピュータ上で文字を扱う場合、典型的には文字による通信を行う場合にその両端点\ では、"; let (word_wrapper, word_wrapper_width) = - run_composer(Composer::WordWrapper { trim: true }, text, width); - let (line_truncator, _) = run_composer(Composer::LineTruncator, text, width); + run_composer(Composer::WordWrapper { trim: true }, &text, width); + let (line_truncator, _) = run_composer(Composer::LineTruncator, &text, width); assert_eq!(line_truncator, vec!["コンピュータ上で文字"]); let wrapped = vec![ "コンピュータ上で文字", @@ -441,7 +439,7 @@ mod test { assert_eq!(line_truncator, vec![" "]); } - /// Tests an input starting with a letter, followed by spaces - some of the behaviour is + /// Tests an input starting with a letter, folowed by spaces - some of the behaviour is /// incidental. #[test] fn line_composer_char_plus_lots_of_spaces() { @@ -492,21 +490,7 @@ mod test { assert_eq!(word_wrapper, vec!["AAAAAAAAAAAAAAA", "AAAA\u{00a0}AAA",]); // Ensure that if the character was a regular space, it would be wrapped differently. - let text_space = text.replace('\u{00a0}', " "); - 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_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 text_space = text.replace("\u{00a0}", " "); let (word_wrapper_space, _) = run_composer(Composer::WordWrapper { trim: true }, &text_space, width); assert_eq!(word_wrapper_space, vec!["AAAAAAAAAAAAAAA AAAA", "AAA",]); |