Expand description
TC.3b — the sticky-context layer both renderers paint from.
StickyContext is the resolved answer to “which source lines are pinned
above this pane’s text, and what do they look like”. It is built by
cells_worker in the same pass that builds the pane’s
DisplayMatrix and
IndentGuides, from the same snapshot
and stamped with the same MatrixVersion — so the three cannot disagree
and this layer needs no staleness axis of its own.
§Why the rows are built here rather than copied by the renderer
A context header is, by construction, a line that has scrolled ABOVE the
viewport. The CellMatrix is chunked above 4 × viewport_height lines, so
a header three thousand lines up is routinely not resident in any built
chunk. A renderer copying from the published matrix would find nothing and
have to fall back to unhighlighted text — a visible colour flicker on
scroll, which the UX contract vetoes.
The worker holds the rope, the syntax snapshot and the cell builder, so it can build a row for any line whether or not a chunk covers it. That is also what makes the highlighting identical to the document’s rather than merely similar: there is one derivation, not two.
§Why it is keyed by pane and not by buffer
Every other per-pane layer is keyed by BufferId, which means two panes
showing one buffer share it. IndentGuides gets away with that by
publishing block extents and letting each renderer pick the active one from
its own cursor. Context cannot: the ROWS differ per pane, not just which one
is emphasised. One buffer open in two splits with cursors in different
scopes must show different context.
Design: docs/dev/architecture/treesitter-context.md.
Structs§
- Sticky
Context - The pane’s pinned context strip, outermost scope first.
- Sticky
Context Row - One pinned context row: the source line it mirrors, and its cells.