Fix off-by-one errors in syntax highlighting (#14780)

In the case that a line ended with a 0-length run, we would get our
highlights offset by one position.

Release Notes:

- Fixed syntax highlights being offset from syntax in diagnostics
popovers.
This commit is contained in:
Conrad Irwin 2024-07-18 22:37:30 -06:00 committed by GitHub
parent be45f32753
commit 87457f9ae8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 7 deletions

View file

@ -376,7 +376,7 @@ impl WindowTextSystem {
runs: &[TextRun],
wrap_width: Option<Pixels>,
) -> Result<SmallVec<[WrappedLine; 1]>> {
let mut runs = runs.iter().cloned().peekable();
let mut runs = runs.iter().filter(|run| run.len > 0).cloned().peekable();
let mut font_runs = self.font_runs_pool.lock().pop().unwrap_or_default();
let mut lines = SmallVec::new();
@ -444,7 +444,7 @@ impl WindowTextSystem {
// Skip `\n` character.
line_start = line_end + 1;
if let Some(run) = runs.peek_mut() {
run.len = run.len.saturating_sub(1);
run.len -= 1;
if run.len == 0 {
runs.next();
}