ui: Fix panic in highlight_ranges when given an oob index (#39051)

Fixes ZED-1QW

Release Notes:

- Fixed a panic when highlighting labels
This commit is contained in:
Lukas Wirth
2025-09-28 11:54:18 +00:00
committed by GitHub
parent 6d7a4c441b
commit 5ce7eda8d2
@@ -105,15 +105,10 @@ pub fn highlight_ranges(
let mut end_ix = start_ix; let mut end_ix = start_ix;
loop { loop {
end_ix = end_ix + text[end_ix..].chars().next().unwrap().len_utf8(); end_ix += text[end_ix..].chars().next().map_or(0, |c| c.len_utf8());
if let Some(&next_ix) = highlight_indices.peek() if highlight_indices.next_if(|&ix| ix == end_ix).is_none() {
&& next_ix == end_ix break;
{
end_ix = next_ix;
highlight_indices.next();
continue;
} }
break;
} }
highlights.push((start_ix..end_ix, style)); highlights.push((start_ix..end_ix, style));