MingaEditor.DisplayMap (Minga v0.1.0)

Copy Markdown View Source

Unified buffer-line-to-display-row mapping.

Merges per-window folds (FoldMap), per-buffer decoration folds (Decorations.FoldRegion), virtual lines (Decorations.VirtualText with :above/:below placement), and block decorations into a single authoritative mapping.

The DisplayMap is the single source of truth for translating between buffer line numbers and screen row positions. It replaces FoldMap.VisibleLines.compute/4 in the render pipeline.

Design

The DisplayMap is a pure data structure built once per frame from:

  1. Per-window FoldMap folds (code folds, per-window)
  2. Per-buffer decoration folds (closed fold regions from Decorations)
  3. Virtual lines from decorations (:above/:below)
  4. Block decorations (custom-rendered lines between buffer lines)

The map produces a list of entry() tuples describing what to render at each display row, compatible with the existing content rendering pipeline.

Summary

Types

What to render at a display row.

t()

The computed display map for a viewport.

Functions

Returns the display row for a buffer line, or nil if hidden.

Returns true when folds, virtual lines, or block decorations require a display map.

Returns the entry list for the content renderer.

Types

entry()

@type entry() ::
  {non_neg_integer(), :normal}
  | {non_neg_integer(), {:fold_start, pos_integer()}}
  | {non_neg_integer(),
     {:decoration_fold, Minga.Core.Decorations.FoldRegion.t()}}
  | {non_neg_integer(), {:virtual_line, Minga.Core.Decorations.VirtualText.t()}}
  | {non_neg_integer(),
     {:block, Minga.Core.Decorations.BlockDecoration.t(), non_neg_integer()}}

What to render at a display row.

  • {buf_line, :normal} — render the buffer line normally
  • {buf_line, {:fold_start, hidden_count}} — render with fold summary
  • {buf_line, {:decoration_fold, fold_region}} — render with custom placeholder
  • {buf_line, {:virtual_line, virtual_text}} — render a virtual line (no buffer line)
  • {buf_line, {:block, block_decoration, line_index}} — render a block decoration row

t()

@type t() :: %MingaEditor.DisplayMap{entries: [entry()]}

The computed display map for a viewport.

Functions

compute(fold_map, decorations, first_buf_line, visible_rows, total_lines, content_width \\ 80)

Computes the display map for a viewport.

Returns nil when there are no folds, decoration folds, virtual lines, or block decorations, signaling the caller to use the faster sequential path.

Arguments

  • fold_map — per-window FoldMap (code folds)
  • decorations — per-buffer Decorations
  • first_buf_line — first buffer line to display (from viewport scroll)
  • visible_rows — number of screen rows available
  • total_lines — total lines in the buffer
  • content_width — available width for block decoration render callbacks (default 80)

display_row_for_buf_line(display_map, buf_line)

@spec display_row_for_buf_line(t(), non_neg_integer()) :: non_neg_integer() | nil

Returns the display row for a buffer line, or nil if hidden.

required?(fold_map, decorations)

Returns true when folds, virtual lines, or block decorations require a display map.

to_visible_line_map(display_map)

@spec to_visible_line_map(t()) :: [entry()]

Returns the entry list for the content renderer.