# `ElementorexCms.Editor.History`
[🔗](https://github.com/rocket4ce/elementorex_cms/blob/v0.1.0/lib/elementorex_cms/editor/history.ex#L1)

Undo and redo for the editor: snapshots of the document with a label.

Edits of the same field that follow each other quickly (typing in an input)
are merged into one step, so undo goes back a whole word and not a letter.

# `entry`

```elixir
@type entry() :: %{doc: map(), label: String.t(), at: integer()}
```

# `t`

```elixir
@type t() :: %ElementorexCms.Editor.History{
  future: [entry()],
  last: term(),
  limit: pos_integer(),
  past: [entry()]
}
```

# `can_redo?`

Whether there is something to redo.

# `can_undo?`

Whether there is something to undo.

# `new`

```elixir
@spec new(keyword()) :: t()
```

An empty history.

# `push`

```elixir
@spec push(t(), map(), String.t(), term()) :: t()
```

Records `previous` (the document before a change) under `label`. `key`
identifies the edited field: consecutive changes with the same key within
1500 ms are merged.

# `redo`

```elixir
@spec redo(t(), map()) :: {:ok, map(), t()} | :error
```

Goes one step forward. Returns `{:ok, document, history}` or `:error`.

# `restore`

```elixir
@spec restore(t(), map(), non_neg_integer()) :: {:ok, map(), t()} | :error
```

Jumps to step `index` of `past` (0 is the most recent), keeping the steps in
between as redo steps.

# `undo`

```elixir
@spec undo(t(), map()) :: {:ok, map(), t()} | :error
```

Goes one step back. Returns `{:ok, document, history}` or `:error`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
