From a37f70a488f514cab363343af7da503c67a43475 Mon Sep 17 00:00:00 2001 From: Alex Vinyals Date: Mon, 14 Oct 2024 09:11:16 +0200 Subject: [PATCH] bug: tab to str conversion should check the length of the tab in the palette --- helix-term/src/ui/trailing_whitespace.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/helix-term/src/ui/trailing_whitespace.rs b/helix-term/src/ui/trailing_whitespace.rs index 96c9d93b2..6f847138c 100644 --- a/helix-term/src/ui/trailing_whitespace.rs +++ b/helix-term/src/ui/trailing_whitespace.rs @@ -18,7 +18,7 @@ pub fn to_str(self, palette: &WhitespacePalette) -> &str { WhitespaceKind::NonBreakingSpace => &palette.nbsp, WhitespaceKind::NarrowNonBreakingSpace => &palette.nnbsp, WhitespaceKind::Tab => { - let grapheme_tab_width = char_to_byte_idx(&palette.tab, 1); + let grapheme_tab_width = char_to_byte_idx(&palette.tab, palette.tab.len()); &palette.tab[..grapheme_tab_width] } WhitespaceKind::Newline | WhitespaceKind::None => "", @@ -97,7 +97,7 @@ fn palette() -> WhitespacePalette { space: "S".into(), nbsp: "N".into(), nnbsp: "M".into(), - tab: "T".into(), + tab: "".into(), virtual_tab: "V".into(), newline: "L".into(), } @@ -134,7 +134,7 @@ fn test_trailing_whitespace_tracker_correctly_tracks_sequences() { assert_eq!(5, from); assert_eq!(8, to); - assert_eq!("SNMT", content); + assert_eq!("SNM", content); // Now we break the sequence sut.track(6, WhitespaceKind::None); @@ -152,7 +152,7 @@ fn test_trailing_whitespace_tracker_correctly_tracks_sequences() { let (content, from, to) = capture(&mut sut); assert_eq!(10, from); assert_eq!(13, to); - assert_eq!("TNMS", content); + assert_eq!("NMS", content); // Verify compression works sut.track(20, WhitespaceKind::Space); @@ -168,6 +168,6 @@ fn test_trailing_whitespace_tracker_correctly_tracks_sequences() { let (content, from, to) = capture(&mut sut); assert_eq!(20, from); assert_eq!(26, to); // Compression means last tracked token is on 26 instead of 28 - assert_eq!("SSNNMMTTT", content); + assert_eq!("SSNNMM", content); } }