diff --git a/src/views/highlight.rs b/src/views/highlight.rs index 1251e0c..78620c9 100644 --- a/src/views/highlight.rs +++ b/src/views/highlight.rs @@ -1,4 +1,4 @@ -use std::collections::HashSet; +use std::collections::{HashMap, HashSet}; use std::sync::LazyLock; use ratatui::style::{Modifier, Style}; @@ -220,6 +220,12 @@ pub fn highlight_line_with_runtime( let theme = theme::get(); let annotation_style = Style::default().fg(theme.ui.text_dim); + // Keep only the last resolved value per span (at-loops produce one per iteration) + let mut last_resolved: HashMap = HashMap::new(); + for (span, display) in resolved { + last_resolved.insert(span.start, display.as_str()); + } + for token in &tokens { if token.start > last_end { result.push((gap_style, line[last_end..token.start].to_string(), false)); @@ -244,10 +250,8 @@ pub fn highlight_line_with_runtime( result.push((style, line[token.start..token.end].to_string(), false)); - for (span, display) in resolved { - if token.start == span.start as usize { - result.push((annotation_style, format!(" [{display}]"), true)); - } + if let Some(display) = last_resolved.get(&(token.start as u32)) { + result.push((annotation_style, format!(" [{display}]"), true)); } last_end = token.end;