# `Minga.Editing.Operator`
[🔗](https://github.com/jsmestad/minga/blob/main/lib/minga/editing/operator.ex#L1)

Operator functions for the Minga editor: delete, change, and yank.

Each function takes a `Buffer.Server` PID and two positions, and applies
the operator to the text between those positions.

## Position semantics

All range functions use **inclusive** bounds — both `from` and `to` positions
are included in the operation.  Positions are automatically normalised, so
`from` may be greater than `to`.

## Return values

* `delete/3` — `{:ok, :deleted}` after removing the range.
* `change/3` — `{:ok, :changed}` after removing the range (caller should
  then switch to Insert mode).
* `yank/3`  — `{:ok, yanked_text}` without modifying the buffer.

## Line-wise helpers

`delete_line/2`, `change_line/2`, and `yank_line/2` operate on an entire
line by index (zero-based).

# `position`

```elixir
@type position() :: Minga.Buffer.Document.position()
```

A zero-indexed {line, col} cursor position.

# `change`

```elixir
@spec change(GenServer.server(), position(), position()) :: {:ok, :changed}
```

Deletes the text between `from` and `to` (inclusive), just like `delete/3`.
The caller is expected to transition to Insert mode afterward.
Returns `{:ok, :changed}`.

# `change_line`

```elixir
@spec change_line(GenServer.server(), non_neg_integer()) :: {:ok, :changed}
```

Deletes the entire line at `line_index`, just like `delete_line/2`.
The caller is expected to transition to Insert mode afterward.
Returns `{:ok, :changed}`.

# `delete`

```elixir
@spec delete(GenServer.server(), position(), position()) :: {:ok, :deleted}
```

Deletes the text between `from` and `to` (inclusive) in the buffer managed
by `server`.  Positions are automatically normalised.
Returns `{:ok, :deleted}`.

# `delete_line`

```elixir
@spec delete_line(GenServer.server(), non_neg_integer()) :: {:ok, :deleted}
```

Deletes the entire line at `line_index` (zero-based) from the buffer.

If the buffer has more than one line, the trailing newline (or preceding
newline for the last line) is also removed so no blank line is left.
Returns `{:ok, :deleted}`.

# `yank`

```elixir
@spec yank(GenServer.server(), position(), position()) :: {:ok, String.t()}
```

Returns the text between `from` and `to` (inclusive) without modifying the buffer.
Returns `{:ok, yanked_text}`.

# `yank_line`

```elixir
@spec yank_line(GenServer.server(), non_neg_integer()) :: {:ok, String.t()}
```

Returns the full text of the line at `line_index` (including newline separator
where present) without modifying the buffer.
Returns `{:ok, yanked_text}`.

---

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