pub enum Edit {
InsertChar {
at: Position,
ch: char,
},
InsertStr {
at: Position,
text: String,
},
DeleteRange {
start: Position,
end: Position,
kind: MotionKind,
},
JoinLines {
row: usize,
count: usize,
with_space: bool,
},
SplitLines {
row: usize,
cols: Vec<usize>,
inserted_space: bool,
},
Replace {
start: Position,
end: Position,
with: String,
},
InsertBlock {
at: Position,
chunks: Vec<String>,
},
DeleteBlockChunks {
at: Position,
widths: Vec<usize>,
},
}Expand description
One unit of buffer mutation. Constructed by the caller (vim
engine, ex command, …) and handed to Buffer::apply_edit.
§Invariants
All Position arguments must satisfy the bounds documented on
Position before the edit is applied. Out-of-bounds positions
are clamped by Buffer::clamp_position inside
Buffer::apply_edit; if the clamped form changes the edit’s
meaning the result is implementation-defined.
See Buffer::apply_edit for post-conditions that hold after
every variant.
Variants§
InsertChar
Insert one char at at. Cursor lands one position past it.
at must be a valid Position. ch must be a single Unicode
scalar. Multi-grapheme content must use Edit::InsertStr.
InsertStr
Insert text (possibly multi-line) at at. Cursor lands at
the end of the inserted content.
at must be a valid Position. text may contain \n — the
buffer splits on newline. CR (\r) is preserved as-is; the host
is responsible for CRLF normalization before insert.
DeleteRange
Delete [start, end) with the given kind.
start <= end in document order. MotionKind controls whether
trailing newlines are consumed:
MotionKind::Char: byte-precise; preserves enclosing newlines.MotionKind::Line: whole rows fromstart.row..=end.row; endpoint columns are ignored.MotionKind::Block: rectangle[start.row..=end.row] × [min_col..=max_col].
JoinLines
J (with_space = true) / gJ (false) — fold count rows
after row into row.
row + count - 1 must be a valid row. count >= 1.
SplitLines
Inverse of JoinLines. Splits row back at each char column
in cols. inserted_space matches the original join so the
inverse can drop the space before splitting.
Replace
Replace [start, end) with with (charwise, may span rows).
Same constraints as Edit::DeleteRange with
MotionKind::Char for the deleted range, plus the insert
constraints from Edit::InsertStr for with.
InsertBlock
Insert one chunk per row, each at (at.row + i, at.col).
Inverse of a blockwise delete; preserves the rectangle even
when rows are ragged shorter than at.col.
DeleteBlockChunks
Inverse of Edit::InsertBlock. Removes widths[i] chars
starting at (at.row + i, at.col). Carrying widths instead
of recomputing means a ragged-row block delete round-trips
exactly.