diff --git a/helix-core/src/doc_formatter.rs b/helix-core/src/doc_formatter.rs index 98a54a1a5..8c8166b1c 100644 --- a/helix-core/src/doc_formatter.rs +++ b/helix-core/src/doc_formatter.rs @@ -336,18 +336,15 @@ impl<'t> DocumentFormatter<'t> { .change_position(visual_x, self.text_fmt.tab_width); word_width += grapheme.width(); } - if let Some(grapheme) = &mut self.peeked_grapheme { - let visual_x = self.visual_pos.col + word_width; - grapheme - .grapheme - .change_position(visual_x, self.text_fmt.tab_width); - } word_width } fn peek_grapheme(&mut self, col: usize, char_pos: usize) -> Option<&GraphemeWithSource<'t>> { - if self.peeked_grapheme.is_none() { - self.peeked_grapheme = self.advance_grapheme(col, char_pos); + match &mut self.peeked_grapheme { + None => self.peeked_grapheme = self.advance_grapheme(col, char_pos), + Some(peeked_grapheme) => peeked_grapheme + .grapheme + .change_position(col, self.text_fmt.tab_width), } self.peeked_grapheme.as_ref() } diff --git a/helix-core/src/doc_formatter/test.rs b/helix-core/src/doc_formatter/test.rs index 8eb909f6f..ea2215e82 100644 --- a/helix-core/src/doc_formatter/test.rs +++ b/helix-core/src/doc_formatter/test.rs @@ -80,6 +80,10 @@ fn softwrap_indentation() { softwrap_text("\t\t\tfoo1 foo2 foo3 foo4 foo5 foo6\n"), " foo1 foo2 \n.foo3 foo4 foo5 \n.foo6 \n " ); + assert_eq!( + softwrap_text("\t\tfoo1\n\t\tfoo2\n\t\tfoo3\n"), + " foo1 \n foo2 \n foo3 \n " + ); } #[test]