text_delta v1.0.2 TextDelta.Attributes
Attributes represent format associated with TextDelta.Operation.insert/0
or TextDelta.Operation.retain/0
operations. This library uses maps to
represent attributes.
Same as TextDelta.Delta
, attributes are composable and transformable. This
library does not make any assumptions about attribute types, values or
composition.
Summary
Types
Atom representing transformation priority. Should we prioritise left or right side?
A set of attributes applicable to an operation
Types
Functions
Composes two sets of attributes into one.
Simplest way to think about composing arguments is two maps being merged (in fact, that’s exactly how it is implemented at the moment).
The only thing that makes it different from standard map merge is an optional
keep_nils
flag. This flag controls if we want to cleanup all the null
attributes before returning.
This function is used by TextDelta.Delta.compose/2
.
Examples
iex> TextDelta.Attributes.compose(%{color: "blue"}, %{italic: true})
%{color: "blue", italic: true}
iex> TextDelta.Attributes.compose(%{bold: true}, %{bold: nil}, true)
%{bold: nil}
iex> TextDelta.Attributes.compose(%{bold: true}, %{bold: nil}, false)
%{}
Transforms given attribute set against another.
This function is used by TextDelta.Delta.transform/3
.
Example
iex> TextDelta.Attributes.transform(%{italic: true},
iex> %{bold: true}, :left)
%{bold: true}