Expand description
Editing a Doc.
This is the half of a block editor that has nothing to do with gpui: text
goes in and out of a Text, marks move with it, and blocks split, merge
and indent. Keeping it pure is what makes it testable — the guarantee below
is checked over generated edit sequences, not over the handful of cases
anyone thinks to write down.
The guarantee is [crate::serialize]’s, preserved. Call
Doc::normalize and the document round-trips: serialize, parse, and
nothing moves. An editor that can reach a state its own serializer cannot
express is an editor that corrupts the file on save, and no amount of UI
polish recovers from that.
Normalizing is a save step rather than a keystroke step, and deliberately. Markdown cannot hold a space at the end of a line, but stripping one the moment it is typed takes it away mid-word — so the model carries it and sheds it on the way out, which is what every editor that writes markdown does.
Marks are left-sticky: text typed at the end of a bold run is bold, text typed at its start is not. The caret inherits formatting from the character before it, which is what every editor does and what nobody notices until it is wrong.
Structs§
- Splice
- What a
Doc::replacedid, for anything holding a position it moved.
Enums§
- Shortcut
- A markdown prefix typed at the start of a block, and what it turns it into.
Functions§
- inline_
rule - A closing inline delimiter just typed, and the run it closes.
- shortcut
- Match a markdown prefix at the start of a block, returning it and how many bytes it occupied.