From 5e464fcbb70e83f6f929df3b1aa9604c1ddfd712 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sun, 28 Sep 2025 13:54:18 +0200 Subject: [PATCH] ui: Fix panic in `highlight_ranges` when given an oob index (#39051) Fixes ZED-1QW Release Notes: - Fixed a panic when highlighting labels --- crates/ui/src/components/label/highlighted_label.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/crates/ui/src/components/label/highlighted_label.rs b/crates/ui/src/components/label/highlighted_label.rs index 576d47eda5b802ce4cf2fc97b8dac0b20b43e883..d17f1b552cf3e9f5c01593454871acb06aa94249 100644 --- a/crates/ui/src/components/label/highlighted_label.rs +++ b/crates/ui/src/components/label/highlighted_label.rs @@ -97,15 +97,10 @@ pub fn highlight_ranges( let mut end_ix = start_ix; loop { - end_ix = end_ix + text[end_ix..].chars().next().unwrap().len_utf8(); - if let Some(&next_ix) = highlight_indices.peek() - && next_ix == end_ix - { - end_ix = next_ix; - highlight_indices.next(); - continue; + end_ix += text[end_ix..].chars().next().map_or(0, |c| c.len_utf8()); + if highlight_indices.next_if(|&ix| ix == end_ix).is_none() { + break; } - break; } highlights.push((start_ix..end_ix, style));