pub fn active_indent_guide(
caret_row: u32,
line_count: u32,
rows: Range<u32>,
level_at: impl Fn(u32) -> u32,
) -> Option<(u32, u32, u32)>Expand description
Which indent guide is active (highlighted) for the caret’s line.
Returns (indent_level, start_row, end_row) inclusive, or None when no
guide is active (the caret sits at level 0 with no deeper neighbour).
level_at(row) yields a row’s indent level (content = ceil, blank =
interpolated, matching indent_guide_level); rows are 0-based,
line_count the total.
The scope special-cases are the whole point: on a line that opens a deeper
scope (the next line is more indented) the first child level is
highlighted — the opener’s own level + 1, i.e. one tab stop in from the
opener, regardless of how deep the body actually sits — and symmetrically on
a line that closes one (the line above is more indented). Off a brace line
it is just the caret line’s level. The chosen level is then extended over
the contiguous run of rows at least that deep.
Pinning the highlight to initial + 1 (not the body’s real level) is
deliberate: an over-indented body (opener at col 4, body at col 16) still
lights the guide one stop inside the opener — cell 4 — rather than the
body’s own deep guide. For uniformly-indented code the jump is one level,
so initial + 1 already equals the body level.
rows bounds the outward walk: the guide only paints inside the caller’s
viewport, so the extent search never needs to leave that clamp (the widget
passes its window ± slack; tests pass 0..line_count for the unbounded
behaviour). A caret row outside rows yields None — an off-screen caret’s
scope highlight is not painted anyway.