text_delta v1.4.0 TextDelta.Difference View Source
Document diffing.
Given valid document states A and B, generate a delta that when applied to A will result in B.
Link to this section Summary
Functions
Calculates a difference between two documents in form of new delta
Calculates a difference between two documents in form of new delta
Link to this section Types
Reason for an error.
Result of getting a diff.
An ok/error tuple. Represents either a successful diffing in form of
{:ok, delta}
or an error in form of {:error, reason}
.
Link to this section Functions
Link to this function
diff(first, second)
View Source
diff(TextDelta.state(), TextDelta.state()) :: result()
Calculates a difference between two documents in form of new delta.
Examples
successful application:
iex> doc_a =
iex> TextDelta.new()
iex> |> TextDelta.insert("hello")
iex> doc_b =
iex> TextDelta.new()
iex> |> TextDelta.insert("goodbye")
iex> TextDelta.diff(doc_a, doc_b)
{:ok, %TextDelta{ops: [
%{insert: "g"},
%{delete: 4},
%{retain: 1},
%{insert: "odbye"}]}}
error handling:
iex> doc = TextDelta.retain(TextDelta.new(), 3)
iex> TextDelta.diff(doc, doc)
{:error, :bad_document}
Link to this function
diff!(first, second)
View Source
diff!(TextDelta.state(), TextDelta.state()) :: TextDelta.t() | no_return()
Calculates a difference between two documents in form of new delta.
Equivalent to &TextDelta.Difference.diff/2
, but instead of returning
ok/error tuples raises a RuntimeError
.