Expand description
The change currency: Edit / Patch and the one position-mapping
function every derived position flows through.
A Patch is the sole record of “what changed” produced by a committed
transaction. Selections, diagnostics, snippet stops, and find matches all
move through Patch::map_offset — one function, one contract — so a
position is never maintained two ways and cannot drift out of sync.
Mapping is prefix-preserving: an edit deletes [s, e) and inserts L
bytes at s; a position inside the overwritten prefix keeps its absolute
offset, only the deleted tail beyond the insert clamps, and a pure
deletion collapses its interior to s. Bias matters at exactly one place —
a position sitting on the insertion point. Touching edits can stack several
insertions on one point (a formatter’s TextEdit list, a snippet
expansion); bias then treats the stack as one insertion — Right lands
after all of it, Left before it.