crates/ui/src/input/display_map/README.md
Layered coordinate conversion and code folding for Editor/Input.
Buffer (Rope) Logical text
↓
WrapMap Soft-wrapping (buffer_line ↔ wrap_row)
↓
FoldMap Fold projection (wrap_row ↔ display_row)
↓
DisplayMap Public facade (BufferPos ↔ DisplayPos)
| Type | Fields | Scope | Description |
|---|---|---|---|
BufferPos | { line, col } | public | Logical line/column in Rope |
WrapPos | { row, col } | internal | Visual row after soft-wrapping |
DisplayPos | { row, col } | public | Final visible row after folding |
DisplayMap — Public facadebuffer_pos_to_display_pos() / display_pos_to_buffer_pos()set_fold_candidates(), toggle_fold(), is_folded_at(), clear_folds()on_text_changed(), on_layout_changed(), set_font()adjust_folds_for_edit() — incremental fold/candidate line-delta adjustmentupdate_fold_candidates_for_edit() — region-scoped candidate extraction after editsWrapMap — Soft-wrapping layerBuilt on TextWrapper. Provides buffer ↔ wrap coordinate mapping with prefix sum cache for O(1) line lookups.
FoldMap — Fold projection layerMaintains visible_wrap_rows and reverse mapping. When no folds are active, uses identity mapping (wrap_row == display_row) without Vec allocation.
FoldRange / folding — Fold extractionextract_fold_ranges(tree) — full tree traversal (initial load only)extract_fold_ranges_in_range(tree, byte_range) — region-scoped traversal for edits, skips subtrees outside range