Minga.Editing.Fold.Range (Minga v0.1.0)

Copy Markdown View Source

A foldable range within a buffer.

Value object representing a region that can be folded (collapsed). Produced by fold providers, consumed by FoldMap. Two ranges must not overlap; the fold map enforces this on insertion.

Both start_line and end_line are inclusive, 0-indexed buffer line numbers. A range must span at least two lines (end_line > start_line).

Summary

Types

Kind of fold range. Used by the renderer to pick icons and by org-mode cycling to distinguish heading levels from generic blocks.

t()

A foldable range.

Functions

Returns true if the given buffer line falls within this range (inclusive).

Returns the number of lines hidden when this range is folded (excludes the summary line).

Returns true if the given buffer line is hidden by this fold (inside but not the start line).

Creates a new fold range.

Creates a new fold range, raising on invalid input.

Returns true if two ranges overlap.

Types

kind()

@type kind() :: :block | :comment | :import | :heading

Kind of fold range. Used by the renderer to pick icons and by org-mode cycling to distinguish heading levels from generic blocks.

  • :block — generic code block (function, class, if/for/while)
  • :comment — comment block
  • :import — import/use/require group
  • :heading — org-mode or markdown heading

t()

@type t() :: %Minga.Editing.Fold.Range{
  end_line: non_neg_integer(),
  kind: kind(),
  start_line: non_neg_integer(),
  summary: String.t() | nil
}

A foldable range.

  • start_line — first line of the range (the "summary" line shown when folded)
  • end_line — last line of the range (inclusive)
  • summary — optional text shown after the fold line (e.g., "··· 12 lines")
  • kind — the type of fold range

Functions

contains?(range, line)

@spec contains?(t(), non_neg_integer()) :: boolean()

Returns true if the given buffer line falls within this range (inclusive).

hidden_count(range)

@spec hidden_count(t()) :: pos_integer()

Returns the number of lines hidden when this range is folded (excludes the summary line).

hides?(range, line)

@spec hides?(t(), non_neg_integer()) :: boolean()

Returns true if the given buffer line is hidden by this fold (inside but not the start line).

new(start_line, end_line, opts \\ [])

@spec new(non_neg_integer(), non_neg_integer(), keyword()) ::
  {:ok, t()} | {:error, String.t()}

Creates a new fold range.

Returns {:ok, range} if valid, or {:error, reason} if the range is degenerate (end <= start).

new!(start_line, end_line, opts \\ [])

@spec new!(non_neg_integer(), non_neg_integer(), keyword()) :: t()

Creates a new fold range, raising on invalid input.

overlaps?(range1, range2)

@spec overlaps?(t(), t()) :: boolean()

Returns true if two ranges overlap.