# `Minga.Buffer.UndoPatch`
[🔗](https://github.com/jsmestad/minga/blob/main/lib/minga/buffer/undo_patch.ex#L1)

Reversible byte-range edit for undo and redo history.

A patch records the bytes removed and inserted by one atomic edit, plus the cursor position to restore when that patch is applied. Undo history stores patches instead of full document snapshots so memory usage follows edit size rather than file size.

# `byte_fragment`

```elixir
@type byte_fragment() :: binary()
```

A byte fragment captured from a document diff. It may not be valid standalone UTF-8.

# `t`

```elixir
@opaque t()
```

# `apply`

```elixir
@spec apply(t(), Minga.Buffer.Document.t()) :: Minga.Buffer.Document.t()
```

Applies the patch to a document, returning the previous document state for undo or the next state for redo.

# `from_delta`

```elixir
@spec from_delta(Minga.Buffer.EditDelta.t(), Minga.Buffer.Document.t()) :: t()
```

Builds an undo patch from an edit delta and the document before the edit.

# `from_documents`

```elixir
@spec from_documents(Minga.Buffer.Document.t(), Minga.Buffer.Document.t()) :: t()
```

Builds a minimal byte-range patch from two document versions.

# `invert`

```elixir
@spec invert(t(), Minga.Buffer.Document.t()) :: t()
```

Returns the inverse patch for the current document state.

---

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