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

Owns editor selection semantics for document text.

`Document` stores and mutates the gap buffer. This module decides what a characterwise or linewise selection means, then returns content or a new document from that selection.

# `kind`

```elixir
@type kind() :: :characterwise | :linewise
```

# `t`

```elixir
@type t() :: %Minga.Buffer.Selection{
  cursor: Minga.Buffer.Document.position(),
  kind: kind(),
  span: Minga.Buffer.Span.t()
}
```

# `characterwise`

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

Builds a characterwise selection between two editor positions.

# `clear_line`

```elixir
@spec clear_line(Minga.Buffer.Document.t(), non_neg_integer()) ::
  {String.t(), Minga.Buffer.Document.t()}
```

Clears one line and leaves an empty line behind.

# `contents`

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

Returns the selected text.

# `delete`

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

Deletes a selection and places the cursor where that selection began.

# `length`

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

Returns the grapheme length of the selected text without constructing a new string.

# `line_contents`

```elixir
@spec line_contents(Minga.Buffer.Document.t(), non_neg_integer(), non_neg_integer()) ::
  String.t()
```

Returns the joined text for a linewise selection, without a trailing newline.

# `linewise`

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

Builds a linewise selection between two line numbers.

---

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