Skip to main content

build_indent_guides

Function build_indent_guides 

Source
pub fn build_indent_guides<F, I>(
    shapes_from: F,
    line_count: u32,
    unit: &IndentUnit,
    lo: u32,
    hi: u32,
    version: MatrixVersion,
) -> IndentGuides
where F: Fn(u32) -> I, I: Iterator<Item = LineShape>,
Expand description

Build the guide layer for the source lines [lo, hi).

shapes_from(i) yields source line i and every line after it; the caller supplies it so this stays testable without a rope and so the worker can reuse whatever line access it already holds. hi is clamped by the caller to the buffer’s content line count.

Why a stream and not line(i). The walk covers [walk_start, hi), which below cells_worker’s window cap is the whole document, and it runs on every publish — every keystroke. Reading that range one index at a time costs one O(log n) rope descent per line; reading it from a single stream costs one descent plus a linear walk. The only random access left is the look-back probe, which is bounded by [MAX_LOOKBACK] and in practice stops within a few lines.

The walk starts above lo (see [MAX_LOOKBACK]) so a block opened off the top of the window still paints inside it. It does not extend below hi: a block still open at the end of the walk is closed at the last content line, which is at or below the last visible row, so painting and the cursor-membership test are both unaffected.