pub struct EditDelta {
pub start_line: u32,
pub lines_removed: u32,
pub lines_added: u32,
pub old_end_at_bol: bool,
}Expand description
One applied edit’s line-shift impact on the cell matrix.
All fields are in logical source lines (pre-fold). The edit
removed lines_removed lines starting at start_line (in the
pre-edit document) and inserted lines_added lines starting at
start_line (in the post-edit document).
start_line == 0, lines_removed == 0, lines_added == 0
represents the no-op identity; constructors don’t filter
trivial deltas — the cell-builder’s eligibility check does.
Copy so the publisher can stamp it onto each
CellsRenderState without an Arc bump.
Fields§
§start_line: u32First source line the edit touches in the pre-edit document (also: first line in the post-edit document where the insert content begins). 0-based.
lines_removed: u32Number of full source lines removed. A single-line edit
that doesn’t cross a newline yields 0.
lines_added: u32Number of full source lines added. A single-line insert
without a newline yields 0.
old_end_at_bol: boolWhether the edit’s OLD (pre-edit) range ends at column
(byte) 0 of its last line — i.e. a genuine line boundary
(BOL of the line one past Self::pre_edit_end_line) —
rather than partway into (or at the very end of) that line.
This is the bit lines_removed/lines_added cannot carry:
they are a tree-sitter-shaped row delta (`old_end_position.line
- start_line
), which counts the same for "range ends at BOL of the following line" (the line atpre_edit_end_lineis genuinely untouched) and "range ends at EOL of its own last line" (that line's content WAS the edit). Only this flag disambiguates the two. See [Self::suffix_start_line`].
Defaults to false (the conservative reading: treat the
boundary line as edited rather than risk reusing a wrongly
stale row) so construction sites that don’t care about this
axis — most tests, most benches — can use
..Default::default() without silently opting into the
unsafe reuse.
Implementations§
Source§impl EditDelta
impl EditDelta
Sourcepub fn net_delta(&self) -> i32
pub fn net_delta(&self) -> i32
Net line shift the edit causes for downstream lines.
lines_added - lines_removed as an i32 — can be
negative (deletion shrinks the document).
Sourcepub fn pre_edit_end_line(&self) -> u32
pub fn pre_edit_end_line(&self) -> u32
First source line past the edit’s pre-edit affected range,
counting only full lines removed
(start_line + lines_removed).
This does NOT by itself mean “lines >= this value were
untouched” — that claim only holds when
Self::old_end_at_bol is true (the old range ended
exactly at BOL of this line). When it’s false, the edit’s
old range ended partway into (or at the very end of) THIS
line, so this line’s content was itself part of the edit.
Callers that need the actual safe shift boundary want
Self::suffix_start_line, not this method directly.
Sourcepub fn post_edit_end_line(&self) -> u32
pub fn post_edit_end_line(&self) -> u32
First source line past the edit’s post-edit affected range
(exclusive). Lines >= this value in the post-edit
document map to lines >= pre_edit_end_line in the
pre-edit document.
Sourcepub fn suffix_start_line(&self) -> u32
pub fn suffix_start_line(&self) -> u32
First source line that is safe to treat as an untouched
SUFFIX of the edit — i.e. every line >= this value can be
reused verbatim from the pre-edit cache and shifted
wholesale by Self::net_delta. This is the value
pre_edit_end_line’s doc comment used to (incorrectly)
claim for itself; this method is the one that actually
honours that contract.
Three shapes, in order:
- Pure insert (
lines_removed == 0):pre_edit_end_line() == start_line, which would misclassify the very line the edit lands on (typed into, or split by a newline) as an untouched suffix. The safe boundary is one line later,start_line + 1. - Boundary line partially or wholly replaced
(
lines_removed > 0andold_end_at_bol == false):pre_edit_end_line()lands ON the line the edit’s old range actually ends inside — that line’s content changed, so it is NOT a safe suffix start either. The safe boundary is one line later,pre_edit_end_line() + 1. Table-mode’srewrite()and org’sreplace_linesboth build edits shaped exactly this way (range end = EOL of the last affected line, never BOL of the line after) on every invocation. - Clean line-boundary replace (
lines_removed > 0andold_end_at_bol == true): the old range ended exactly at BOL ofpre_edit_end_line(), so that line is genuinely untouched and safe to shift wholesale —pre_edit_end_line()itself is the answer.