pub struct TextEdit {
pub range: TextRange,
pub replacement: String,
}Expand description
A single-range text edit.
Shaped to mirror LSP TextEdit / rust-analyzer’s TextEdit: a byte
range inside the old source text plus the UTF-8 replacement string.
§Construction
Use TextEdit::replace for a generic range replacement, or
TextEdit::insert for a zero-length insertion at a single offset.
§Coordinate space
The range is in byte offsets over the old source, not characters
and not LSP UTF-16 columns. Callers that start from LSP ranges must
translate first (see crate::LineIndex).
Fields§
§range: TextRangeByte range (inside the old source) that is replaced.
replacement: StringUTF-8 replacement text. Empty string = deletion.
Implementations§
Source§impl TextEdit
impl TextEdit
Sourcepub fn replace(range: TextRange, replacement: impl Into<String>) -> Self
pub fn replace(range: TextRange, replacement: impl Into<String>) -> Self
Build a replace-range edit.
range is in byte offsets over the old source text. The
replacement is owned to keep the edit value trivially movable.
Sourcepub fn insert(offset: TextSize, text: impl Into<String>) -> Self
pub fn insert(offset: TextSize, text: impl Into<String>) -> Self
Build a pure insertion at offset.
Sourcepub fn apply(&self, src: &str) -> String
pub fn apply(&self, src: &str) -> String
Apply this edit to src, returning the resulting text.
Offsets that exceed src.len() are clamped to the end of the
source (matching String::replace_range’s implicit behaviour).
Both endpoints of range are rounded down to the previous
UTF-8 char boundary if they fall in the middle of a multi-byte
sequence; callers feeding ASCII-only Cypher never hit this path.