Skip to main content

Module display_map

Module display_map 

Source
Expand description

The display map: buffer coordinates ↔ display coordinates, tab expansion only.

This module owns both coordinate spaces and the sole converter between them. Buffer space is Point (row + byte column); display space is DisplayPoint (row + cell column, one cell = one Unicode scalar’s monospace advance, a tab = 1..=tab_size cells). The seam is a concrete type — TabMap — not a trait: the one other implementor, crate::fold_map::FoldMap, composes over this surface rather than sharing a dyn bound, and word wrap is rejected (it belongs in a rich-text editor, not a code editor), so no further implementor is expected.

What freezes the callable set against the widget crate is not a dyn bound but the pub(crate) constructor on DisplayPoint/DisplayRow: every display coordinate in existence came out of a TabMap method, so no code in scrive-iced can fabricate one — it must go through TabMap::to_display/TabMap::clip. Cross-space arithmetic is a compile error, which is the enforcement of “no widget code does row/column math across spaces.”

The TabMap itself is row-preserving: DisplayRow(r) ⇔ buffer row r, rows never move, only columns stretch. A caret can never rest inside a tab expansion — the bias snap in collapse forbids it. Folding sits as a layer above (crate::fold_map::FoldMap hides rows / collapses inline spans over this base) without changing any signature here; word wrap is rejected, not deferred.

Structs§

BufferRow
A buffer row, 0-based — the gutter’s printed line number.
DisplayChunk
One render run of a display row, split at every tab boundary so the renderer can draw tab invisibles and overlay highlight spans onto each run.
DisplayChunks
Lazy per-row splitter yielding one DisplayChunk per run, tabs isolated. Constructed by chunks over a line the CALLER holds — the caller materializes the row (one Buffer::line Cow) and the runs borrow from it, so no iterator owns text it also lends out.
DisplayEdit
A display-space edit region: what TabMap::sync would return if a display-space invalidation reader ever appeared. There is none today — the FoldMap re-derives per frame and word wrap is rejected — so sync returns () and downstream caches (line cache, paragraph cache) invalidate off the buffer-space edit they already consume.
DisplayPoint
A visual position: display row + cell column (one cell = one Unicode scalar’s monospace advance; a tab occupies 1..=tab_size cells).
DisplayRow
A display row, 0-based. In the tab-only map: DisplayRow(r) ⇔ buffer row r.
TabMap
The coordinates seam — a concrete type, not a trait.

Functions§

active_indent_guide
Which indent guide is active (highlighted) for the caret’s line.
chunks
Split one row’s text into DisplayChunk runs at every tab boundary.
collapse
Cell column → byte column, with the mid-tab bias snap.
default_tab_size
Default tab stop width — 4, the common indent width; a change is one whole-document edit through TabMap::sync.
expand
Byte column → cell column, a per-line scan from column 0.
indent_guide_level
Indentation depth (in guide levels) for one row — the number of indent guides drawn to its left.
tab_width
Expansion width of a tab beginning at 0-based cell column c: advances to the next multiple of tab_size, always 1..=tab_size, never zero.