use concinnity_core::components::ColorRun;
use super::Span;
use crate::editor::text_area::view;
pub(crate) fn window_runs(
line: &str,
spans: &[Span],
left: usize,
width: usize,
out: &mut Vec<ColorRun>,
) {
if spans.is_empty() {
return;
}
let mut cells = Vec::with_capacity(line.len() + 1);
let mut cell = 0;
for c in line.chars() {
cells.push(cell);
cell = view::advance(cell, c);
}
cells.push(cell);
let cell_of = |col: usize| cells[col.min(cells.len() - 1)];
let right = left + width;
for span in spans {
let a = cell_of(span.start).max(left);
let b = cell_of(span.start + span.len).min(right);
if b > a {
out.push(ColorRun {
start: (a - left) as u32,
length: (b - a) as u32,
color: span.token.color(),
});
}
}
}