pub struct LineBuffer { /* private fields */ }Expand description
Fast, indexed line-based text buffer backed by a balanced B-Tree Rope.
Implementations§
Source§impl LineBuffer
impl LineBuffer
Sourcepub fn from_str(text: &str) -> Self
pub fn from_str(text: &str) -> Self
Constructs a LineBuffer by splitting an input string along linebreaks (\n or \r\n).
Sourcepub fn rope_mut(&mut self) -> &mut TextRope
pub fn rope_mut(&mut self) -> &mut TextRope
Accesses the underlying balanced B-Tree TextRope mutably.
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 (excluding \n separators).
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, pos: Position) -> usize
pub fn position_to_byte(&self, pos: Position) -> usize
Computes the exact byte offset of pos in the \n-joined document in O(log N).
Sourcepub fn position_to_point(&self, pos: Position) -> Point
pub fn position_to_point(&self, pos: Position) -> Point
Computes the Tree-Sitter Point (byte column) for pos.
Sourcepub fn byte_to_position(&self, byte_offset: usize) -> Position
pub fn byte_to_position(&self, byte_offset: usize) -> Position
Converts a byte offset in the \n-joined document into a character Position 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 buffer.
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.
Trait Implementations§
Source§impl Clone for LineBuffer
impl Clone for LineBuffer
Source§impl Debug for LineBuffer
impl Debug for LineBuffer
Source§impl Default for LineBuffer
impl Default for LineBuffer
Source§impl Display for LineBuffer
impl Display for LineBuffer
impl Eq for LineBuffer
Source§impl FromStr for LineBuffer
impl FromStr for LineBuffer
Source§impl PartialEq for LineBuffer
impl PartialEq for LineBuffer
impl StructuralPartialEq for LineBuffer
Auto Trait Implementations§
impl Forget for LineBuffer
impl Freeze for LineBuffer
impl Move for LineBuffer
impl RefUnwindSafe for LineBuffer
impl Send for LineBuffer
impl Sync for LineBuffer
impl Unpin for LineBuffer
impl UnsafeUnpin for LineBuffer
impl UnwindSafe for LineBuffer
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.