Expand description
The atomic multi-range transaction engine.
Every change to a Buffer — typing, paste, undo, redo, programmatic —
goes through apply: one mutation path, so an inverse can never drift
from what was applied — the inverse is derived mechanically from the same
normalized batch, never hand-written. The contract, in order:
- clip each op’s range to the pre-edit document (char boundaries) and normalize its text to LF;
- stable-sort ops ascending by start, ties in caller order (so two inserts at one offset apply in the order the caller gave them);
- overlap is a programmer error →
Err(debug-panics); - capture each op’s replaced text before mutating, and build both the
forward
Patchand the inverse ops (delta-chained on the sorted list); - apply descending so offsets stay valid; drop no-ops; an empty batch is no transaction at all (the revision does not move).
Undo and redo are just apply fed the inverse ops — the
Committed::inverse_ops of one call are the input of the next.
Structs§
- Committed
- The result of a committed transaction.
- EditOp
- One replacement: put
textwhererangecurrently is.rangeis in pre-edit byte coordinates; an emptyrangewith emptytextis a no-op and is dropped.
Enums§
- Transaction
Error - A transaction could not be applied.