text_delta v1.3.0 TextDelta.Attributes View Source

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, attributes are composable and transformable. This library does not make any assumptions about attribute types, values or composition.

Link to this section Summary

Types

Atom representing transformation priority. Should we prioritise left or right side?

t()

A set of attributes applicable to an operation

Functions

Composes two sets of attributes into one

Calculates and returns difference between two sets of attributes

Transforms right attribute set against the left one

Link to this section Types

Link to this type priority() View Source
priority() :: :left | :right

Atom representing transformation priority. Should we prioritise left or right side?

A set of attributes applicable to an operation.

Link to this section Functions

Link to this function compose(first, second, keep_nils \\ false) View Source
compose(t(), t(), boolean()) :: t()

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.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)
%{}
Link to this function diff(attrs_a, attrs_b) View Source
diff(t(), t()) :: t()

Calculates and returns difference between two sets of attributes.

Given an initial set of attributes and the final one, this function will generate an attribute set that is when composed with original one would yield the final result.

Examples

iex> TextDelta.Attributes.diff(%{font: “arial”, color: “blue”}, iex> %{color: “red”}) %{font: nil, color: “red”}

Link to this function transform(left, right, priority) View Source
transform(t(), t(), priority()) :: t()

Transforms right attribute set against the left one.

The function also takes a third TextDelta.Attributes.priority/0 argument that indicates which set came first.

This function is used by TextDelta.transform/3.

Example

iex> TextDelta.Attributes.transform(%{italic: true},
iex>                                %{bold: true}, :left)
%{bold: true}