pub struct ChangeSet { /* private fields */ }Expand description
An ordered, position-composable set of changes.
Construct with ChangeSet::builder; the ops are private because the canonical form
(merged runs, Delete before Insert at a replacement site) is an invariant that
compose and map_pos rely on.
Implementations§
Source§impl ChangeSet
impl ChangeSet
pub fn builder(len_before: usize) -> ChangeSetBuilder
Sourcepub fn replace(
len_before: usize,
from: usize,
to: usize,
text: impl Into<String>,
) -> Self
pub fn replace( len_before: usize, from: usize, to: usize, text: impl Into<String>, ) -> Self
A single replacement: replace chars from..to with text. The common shape for a
keystroke, a paste, or one hunk of an agent diff.
pub fn len_before(&self) -> usize
pub fn len_after(&self) -> usize
pub fn ops(&self) -> &[Operation]
Sourcepub fn is_identity(&self) -> bool
pub fn is_identity(&self) -> bool
Whether this changes nothing (every char retained, nothing inserted).
pub fn changed_span(&self) -> Option<ChangedSpan>
Sourcepub fn apply(&self, text: &Rope) -> Rope
pub fn apply(&self, text: &Rope) -> Rope
Produce the changed document. Does not mutate the input — the caller decides when a new revision becomes current.
Sourcepub fn invert(&self, original: &Rope) -> ChangeSet
pub fn invert(&self, original: &Rope) -> ChangeSet
The changeset that undoes this one.
Needs the pre-image because Operation::Delete does not record what it deleted.
Per ADR-0006 §6 this is called at apply time, while original is still the live
document — calling it at undo time would hand it the post-image.
Sourcepub fn map_pos(&self, pos: usize, assoc: Assoc) -> usize
pub fn map_pos(&self, pos: usize, assoc: Assoc) -> usize
Where pos (an index into the pre-image) lands in the post-image.
Positions inside a deleted range collapse to the start of the deletion — the text they pointed at is gone, and the start of what replaced it is the only honest answer. Callers that need to detect that case compare against the deletion instead of relying on the mapped value (ADR-0006 §4).
Sourcepub fn touches(&self, from: usize, to: usize) -> RangeEffect
pub fn touches(&self, from: usize, to: usize) -> RangeEffect
What this change did to from..to — a range something else is anchored to.
map_pos cannot answer this, by construction. It collapses a
position inside a deleted range onto the deletion point, which is the same value
it returns for a position at the deletion’s start that was never destroyed; and it
sees nothing at all when text is inserted inside a range, since both endpoints
shift cleanly. Both are exactly the signals ADR-0006 §4 cases 2 and 4 turn on, so
they get their own traversal rather than being re-derived from the outside.
A zero-width range is an anchor: it counts as deleted only if the deletion strictly contains it, since a deletion merely starting there leaves it standing.