View Source Yex.Text (y_ex v0.6.3)

A shareable type that is optimized for shared editing on text.

Summary

Types

@type delta() ::
  [%{:insert => Yex.input_type(), optional(:attributes) => map()}]
  | [%{delete: integer()}]
  | [%{:retain => integer(), optional(:attributes) => map()}]
@type t() :: %Yex.Text{doc: reference(), reference: reference()}

Functions

Link to this function

apply_delta(text, delta)

View Source
@spec apply_delta(t(), delta()) :: :ok | :error

Transforms this type to a Quill Delta

Examples Sync two clients by exchanging the complete document structure

iex> doc = Yex.Doc.new()
iex> text = Yex.Doc.get_text(doc, "text")
iex> delta = [%{ "retain" => 1}, %{ "delete" => 3}]
iex> Yex.Text.insert(text,0, "12345")
iex> Yex.Text.apply_delta(text,delta)
iex> Yex.Text.to_delta(text)
[%{insert: "15"}]
Link to this function

delete(text, index, length)

View Source
@spec delete(t(), integer(), integer()) :: :ok | :error
Link to this function

format(text, index, length, attr)

View Source
@spec format(t(), integer(), integer(), map()) :: :ok | :error
Link to this function

insert(text, index, content)

View Source
@spec insert(t(), integer(), Yex.input_type()) :: :ok | :error
Link to this function

insert(text, index, content, attr)

View Source
@spec insert(t(), integer(), Yex.input_type(), map()) :: :ok | :error
@spec length(t()) :: integer()
@spec to_delta(t()) :: delta()

Transforms this type to a Quill Delta

Examples Sync two clients by exchanging the complete document structure

iex> doc = Yex.Doc.new()
iex> text = Yex.Doc.get_text(doc, "text")
iex> Yex.Text.insert(text, 0, "12345")
iex> Yex.Text.insert(text, 0, "0", %{"bold" => true})
iex> Yex.Text.to_delta(text)
[%{insert: "0", attributes: %{"bold" => true}}, %{insert: "12345"}]
@spec to_string(t()) :: binary()