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§
- Buffer
Row - A buffer row, 0-based — the gutter’s printed line number.
- Display
Chunk - 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.
- Display
Chunks - Lazy per-row splitter yielding one
DisplayChunkper run, tabs isolated. Constructed bychunksover a line the CALLER holds — the caller materializes the row (oneBuffer::lineCow) and the runs borrow from it, so no iterator owns text it also lends out. - Display
Edit - A display-space edit region: what
TabMap::syncwould return if a display-space invalidation reader ever appeared. There is none today — theFoldMapre-derives per frame and word wrap is rejected — sosyncreturns()and downstream caches (line cache, paragraph cache) invalidate off the buffer-space edit they already consume. - Display
Point - A visual position: display row + cell column (one cell = one Unicode
scalar’s monospace advance; a tab occupies
1..=tab_sizecells). - Display
Row - A display row, 0-based. In the tab-only map:
DisplayRow(r)⇔ buffer rowr. - 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
DisplayChunkruns 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 oftab_size, always1..=tab_size, never zero.