Skip to main content

EditDelta

Struct EditDelta 

Source
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: u32

First 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: u32

Number of full source lines removed. A single-line edit that doesn’t cross a newline yields 0.

§lines_added: u32

Number of full source lines added. A single-line insert without a newline yields 0.

§old_end_at_bol: bool

Whether 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 at pre_edit_end_line is 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

Source

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).

Source

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.

Source

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.

Source

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 > 0 and old_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’s rewrite() and org’s replace_lines both 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 > 0 and old_end_at_bol == true): the old range ended exactly at BOL of pre_edit_end_line(), so that line is genuinely untouched and safe to shift wholesale — pre_edit_end_line() itself is the answer.

Trait Implementations§

Source§

impl Clone for EditDelta

Source§

fn clone(&self) -> EditDelta

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for EditDelta

Source§

impl Debug for EditDelta

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for EditDelta

Source§

fn default() -> EditDelta

Returns the “default value” for a type. Read more
Source§

impl Eq for EditDelta

Source§

impl PartialEq for EditDelta

Source§

fn eq(&self, other: &EditDelta) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for EditDelta

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more