Skip to content

Commit e51dbf8

Browse files
highlighter: prevent empty range style leaks (#2457)
## Summary - Ignore empty syntax highlight ranges before style merging - Filter empty ranges in `unique_styles` so zero-length captures cannot remain active after their position - Add a focused regression case covering empty ranges leaking styles into later spans ## Screenshots ### Before <img width="1918" height="1078" alt="before" src="https://github.com/user-attachments/assets/284d4a15-e044-4bd3-98c6-2fdf4ea47da3" /> ### After <img width="1918" height="1078" alt="after" src="https://github.com/user-attachments/assets/b07d2021-da2e-4efb-b3ce-90b697203894" />
1 parent 4504e48 commit e51dbf8

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

crates/ui/src/highlighter/highlighter.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,9 @@ impl SyntaxHighlighter {
921921
if node_range.start > node_range.end {
922922
node_range.end = node_range.start;
923923
}
924+
if node_range.is_empty() {
925+
continue;
926+
}
924927

925928
styles.push((node_range, theme.style(name.as_ref()).unwrap_or_default()));
926929
}
@@ -960,6 +963,11 @@ pub(crate) fn unique_styles(
960963
total_range: &Range<usize>,
961964
styles: Vec<(Range<usize>, HighlightStyle)>,
962965
) -> Vec<(Range<usize>, HighlightStyle)> {
966+
let styles: Vec<_> = styles
967+
.into_iter()
968+
.filter(|(range, _)| !range.is_empty())
969+
.collect();
970+
963971
if styles.is_empty() {
964972
return styles;
965973
}
@@ -1392,5 +1400,11 @@ $x = 1;
13921400
(60..65, clean),
13931401
],
13941402
);
1403+
1404+
assert_unique_styles(
1405+
0..10,
1406+
vec![(2..2, red), (4..6, green)],
1407+
vec![(0..4, clean), (4..6, green), (6..10, clean)],
1408+
);
13951409
}
13961410
}

0 commit comments

Comments
 (0)