# `Leaf.Collab.Text`
[🔗](https://github.com/alexdont/leaf/blob/main/lib/leaf/collab/text.ex#L1)

The unit an operation's offsets are counted in.

An editor describes its edit with the numbers its own strings give it:
`at` and `remove` from JavaScript's `length` and `slice`, which count
UTF-16 code units. `String.length/1` counts graphemes, and the two agree
only while the text has nothing outside the Basic Multilingual Plane and
no combining marks — one emoji, and every offset after it is off by one for
the room, which then refuses or misplaces every edit. So the room measures
and cuts the document in the editor's unit.

# `length`

```elixir
@spec length(String.t()) :: non_neg_integer()
```

Length in UTF-16 code units.

# `splice`

```elixir
@spec splice(String.t(), integer(), integer(), String.t()) ::
  {:ok, String.t()} | :error
```

Replaces `remove` code units at `at` with `insert`.

`:error` when the splice points outside the text or would cut a surrogate
pair in half — neither can be applied without scattering characters.

# `utf16`

```elixir
@spec utf16(String.t()) :: binary()
```

The text as big-endian UTF-16, two bytes per code unit.

---

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