text_delta v1.4.0 TextDelta.Document View Source
Document-related logic like splitting it into lines etc.
Link to this section Summary
Link to this section Types
Reason for an error.
Link to this type
line_segments()
View Source
line_segments() :: [{TextDelta.state(), TextDelta.Attributes.t()}]
Line segments.
Each line has a delta of the content on that line (minus ) and a set of
attributes applied to the entire block.
Link to this type
lines_result()
View Source
lines_result() :: {:ok, line_segments()} | {:error, error_reason()}
Result of getting document lines.
An ok/error tuple. Represents either a successful retrieval in form of
{:ok, [line]}
or an error in form of {:error, reason}
.
Link to this section Functions
Breaks document into multiple line segments.
Given document will be split according to newline characters ().
Examples
successful application:
iex> doc =
iex> TextDelta.new()
iex> |> TextDelta.insert("hi\nworld")
iex> |> TextDelta.insert("\n", %{header: 1})
iex> TextDelta.lines(doc)
{:ok, [ {%TextDelta{ops: [%{insert: "hi"}]}, %{}},
{%TextDelta{ops: [%{insert: "world"}]}, %{header: 1}} ]}
error handling:
iex> doc = TextDelta.retain(TextDelta.new(), 3)
iex> TextDelta.lines(doc)
{:error, :bad_document}
Link to this function
lines!(doc)
View Source
lines!(TextDelta.state()) :: line_segments() | no_return()
Breaks document into multiple line segments.
Equivalent to &TextDelta.Document.lines/1
, but instead of returning
ok/error tuples raises a RuntimeError
.