mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-24 10:26:18 +04:00
bug: tab to str conversion should check the length of the tab in the palette
This commit is contained in:
parent
ab57115567
commit
a37f70a488
@ -18,7 +18,7 @@ pub fn to_str(self, palette: &WhitespacePalette) -> &str {
|
|||||||
WhitespaceKind::NonBreakingSpace => &palette.nbsp,
|
WhitespaceKind::NonBreakingSpace => &palette.nbsp,
|
||||||
WhitespaceKind::NarrowNonBreakingSpace => &palette.nnbsp,
|
WhitespaceKind::NarrowNonBreakingSpace => &palette.nnbsp,
|
||||||
WhitespaceKind::Tab => {
|
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]
|
&palette.tab[..grapheme_tab_width]
|
||||||
}
|
}
|
||||||
WhitespaceKind::Newline | WhitespaceKind::None => "",
|
WhitespaceKind::Newline | WhitespaceKind::None => "",
|
||||||
@ -97,7 +97,7 @@ fn palette() -> WhitespacePalette {
|
|||||||
space: "S".into(),
|
space: "S".into(),
|
||||||
nbsp: "N".into(),
|
nbsp: "N".into(),
|
||||||
nnbsp: "M".into(),
|
nnbsp: "M".into(),
|
||||||
tab: "T".into(),
|
tab: "<TAB>".into(),
|
||||||
virtual_tab: "V".into(),
|
virtual_tab: "V".into(),
|
||||||
newline: "L".into(),
|
newline: "L".into(),
|
||||||
}
|
}
|
||||||
@ -134,7 +134,7 @@ fn test_trailing_whitespace_tracker_correctly_tracks_sequences() {
|
|||||||
|
|
||||||
assert_eq!(5, from);
|
assert_eq!(5, from);
|
||||||
assert_eq!(8, to);
|
assert_eq!(8, to);
|
||||||
assert_eq!("SNMT", content);
|
assert_eq!("SNM<TAB>", content);
|
||||||
|
|
||||||
// Now we break the sequence
|
// Now we break the sequence
|
||||||
sut.track(6, WhitespaceKind::None);
|
sut.track(6, WhitespaceKind::None);
|
||||||
@ -152,7 +152,7 @@ fn test_trailing_whitespace_tracker_correctly_tracks_sequences() {
|
|||||||
let (content, from, to) = capture(&mut sut);
|
let (content, from, to) = capture(&mut sut);
|
||||||
assert_eq!(10, from);
|
assert_eq!(10, from);
|
||||||
assert_eq!(13, to);
|
assert_eq!(13, to);
|
||||||
assert_eq!("TNMS", content);
|
assert_eq!("<TAB>NMS", content);
|
||||||
|
|
||||||
// Verify compression works
|
// Verify compression works
|
||||||
sut.track(20, WhitespaceKind::Space);
|
sut.track(20, WhitespaceKind::Space);
|
||||||
@ -168,6 +168,6 @@ fn test_trailing_whitespace_tracker_correctly_tracks_sequences() {
|
|||||||
let (content, from, to) = capture(&mut sut);
|
let (content, from, to) = capture(&mut sut);
|
||||||
assert_eq!(20, from);
|
assert_eq!(20, from);
|
||||||
assert_eq!(26, to); // Compression means last tracked token is on 26 instead of 28
|
assert_eq!(26, to); // Compression means last tracked token is on 26 instead of 28
|
||||||
assert_eq!("SSNNMMTTT", content);
|
assert_eq!("SSNNMM<TAB><TAB><TAB>", content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user