Skip to main content

Module transaction

Module transaction 

Source
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:

  1. clip each op’s range to the pre-edit document (char boundaries) and normalize its text to LF;
  2. stable-sort ops ascending by start, ties in caller order (so two inserts at one offset apply in the order the caller gave them);
  3. overlap is a programmer error → Err (debug-panics);
  4. capture each op’s replaced text before mutating, and build both the forward Patch and the inverse ops (delta-chained on the sorted list);
  5. 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 text where range currently is. range is in pre-edit byte coordinates; an empty range with empty text is a no-op and is dropped.

Enums§

TransactionError
A transaction could not be applied.