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.