pub struct TextRope { /* private fields */ }Expand description
Balanced B-Tree Rope text data structure for logarithmic-time line indexing, splitting, joining, and editing across massive documents (100,000+ lines).
Implementations§
Source§impl TextRope
impl TextRope
Sourcepub fn from_str(text: &str) -> Self
pub fn from_str(text: &str) -> Self
Constructs a TextRope by splitting an input string along linebreaks (\n or \r\n).
Sourcepub fn line_count(&self) -> usize
pub fn line_count(&self) -> usize
Total number of lines in the buffer.
Sourcepub fn total_char_count(&self) -> usize
pub fn total_char_count(&self) -> usize
Total number of characters in the buffer.
Sourcepub fn total_byte_count(&self) -> usize
pub fn total_byte_count(&self) -> usize
Total number of bytes in the buffer.
Sourcepub fn insert_line(&mut self, line_idx: usize, text: String)
pub fn insert_line(&mut self, line_idx: usize, text: String)
Inserts a new line into the B-Tree at index line_idx, maintaining B-Tree balance.
Sourcepub fn delete_line(&mut self, line_idx: usize) -> Option<String>
pub fn delete_line(&mut self, line_idx: usize) -> Option<String>
Deletes the line at index line_idx, collapsing internal nodes if necessary.
Sourcepub fn line(&self, idx: usize) -> Option<&str>
pub fn line(&self, idx: usize) -> Option<&str>
Returns a reference to the line at the specified 0-based index.
Sourcepub fn line_mut(&mut self, idx: usize) -> Option<&mut String>
pub fn line_mut(&mut self, idx: usize) -> Option<&mut String>
Returns a mutable reference to the line at the specified 0-based index.
Sourcepub fn line_len(&self, idx: usize) -> usize
pub fn line_len(&self, idx: usize) -> usize
Returns the character length of the line at the specified index.
Sourcepub fn line_char_count(&self, idx: usize) -> usize
pub fn line_char_count(&self, idx: usize) -> usize
Returns the character count of the line at the specified index.
Sourcepub fn line_byte_len(&self, idx: usize) -> usize
pub fn line_byte_len(&self, idx: usize) -> usize
Returns the byte length of the line at the specified index.
Sourcepub fn insert_char(&mut self, line: usize, col: usize, ch: char)
pub fn insert_char(&mut self, line: usize, col: usize, ch: char)
Inserts a character at the specified line and character column.
Sourcepub fn insert_str(&mut self, line: usize, col: usize, text: &str)
pub fn insert_str(&mut self, line: usize, col: usize, text: &str)
Inserts a string at the specified line and character column, automatically handling multiline breaks.
Sourcepub fn split_line(&mut self, line: usize, col: usize)
pub fn split_line(&mut self, line: usize, col: usize)
Splits a line into two lines at the given character column index.
Sourcepub fn join_line_with_next(&mut self, line: usize)
pub fn join_line_with_next(&mut self, line: usize)
Joins the specified line with the subsequent line.
Sourcepub fn delete_backwards(
&mut self,
line: usize,
col: usize,
) -> Option<(usize, usize)>
pub fn delete_backwards( &mut self, line: usize, col: usize, ) -> Option<(usize, usize)>
Deletes a character before the specified position (backspace).
Sourcepub fn delete_range(
&mut self,
start_line: usize,
start_col: usize,
end_line: usize,
end_col: usize,
) -> String
pub fn delete_range( &mut self, start_line: usize, start_col: usize, end_line: usize, end_col: usize, ) -> String
Deletes text within the given bounding character range and returns the deleted substring.
Sourcepub fn total_text_byte_len(&self) -> usize
pub fn total_text_byte_len(&self) -> usize
Total UTF-8 byte length of the serialized \n-joined document.
Sourcepub fn position_to_byte(&self, line: usize, char_col: usize) -> usize
pub fn position_to_byte(&self, line: usize, char_col: usize) -> usize
Computes the exact byte offset of (line, char_col) in the \n-joined document in O(log N).
Sourcepub fn position_to_point(&self, line: usize, char_col: usize) -> Point
pub fn position_to_point(&self, line: usize, char_col: usize) -> Point
Computes the Tree-Sitter Point { row, column } (byte column within row) for (line, char_col).
Sourcepub fn byte_to_position(&self, byte_offset: usize) -> (usize, usize)
pub fn byte_to_position(&self, byte_offset: usize) -> (usize, usize)
Converts a byte offset in the \n-joined document into (line, char_col) in O(log N).
Sourcepub fn compute_input_edit(
&self,
start: Position,
old_end: Position,
inserted_text: &str,
) -> (InputEdit, Position)
pub fn compute_input_edit( &self, start: Position, old_end: Position, inserted_text: &str, ) -> (InputEdit, Position)
Computes an exact tree_sitter::InputEdit describing replacing [start..old_end) with
inserted_text before applying the mutation to the rope.
Trait Implementations§
impl Eq for TextRope
impl StructuralPartialEq for TextRope
Auto Trait Implementations§
impl Forget for TextRope
impl Freeze for TextRope
impl Move for TextRope
impl RefUnwindSafe for TextRope
impl Send for TextRope
impl Sync for TextRope
impl Unpin for TextRope
impl UnsafeUnpin for TextRope
impl UnwindSafe for TextRope
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.