pub struct ChangeSet { /* private fields */ }Expand description
Sorted, non-overlapping, non-touching edits against a document of base_len
bytes.
Implementations§
Source§impl ChangeSet
impl ChangeSet
Sourcepub fn new(base_len: ByteOffset, edits: Vec<Edit>) -> Self
pub fn new(base_len: ByteOffset, edits: Vec<Edit>) -> Self
Sorts the edits and merges touching ones (concatenating their text) and overlapping deletions. Overlapping edits that both insert text are a caller bug.
pub fn edits(&self) -> &[Edit]
Sourcepub fn fits(&self, doc: &Document) -> bool
pub fn fits(&self, doc: &Document) -> bool
Whether this applies to doc: its length matches, and the edits are
in order and apart (as ChangeSet::new leaves them), inside the
text and on character boundaries. A change set read back from disk
is checked with this before it is used.
pub fn is_empty(&self) -> bool
pub fn base_len(&self) -> ByteOffset
pub fn new_len(&self) -> ByteOffset
Sourcepub fn apply(&self, doc: &mut Document)
pub fn apply(&self, doc: &mut Document)
Applies the edits to doc, which must be in the base state.
Sourcepub fn invert(&self, doc: &Document) -> ChangeSet
pub fn invert(&self, doc: &Document) -> ChangeSet
The change set that undoes this one. doc must be in the base state.
Sourcepub fn map_position(&self, pos: ByteOffset, bias: Bias) -> ByteOffset
pub fn map_position(&self, pos: ByteOffset, bias: Bias) -> ByteOffset
Maps a position in the base state to the new state.
Positions inside a replaced range move to its start (Before) or to the
end of the replacement (After). A position at the start of a non-empty
replaced range stays before it and one at its end stays after it,
whatever the bias; the bias only decides ties at pure insertions and
positions strictly inside a replaced range.