Skip to main content

LineBuffer

Struct LineBuffer 

Source
pub struct LineBuffer { /* private fields */ }
Expand description

Fast, indexed line-based text buffer backed by a balanced B-Tree Rope.

Implementations§

Source§

impl LineBuffer

Source

pub fn new() -> Self

Creates an empty buffer containing a single empty line.

Source

pub fn from_str(text: &str) -> Self

Constructs a LineBuffer by splitting an input string along linebreaks (\n or \r\n).

Source

pub fn rope(&self) -> &TextRope

Accesses the underlying balanced B-Tree TextRope.

Source

pub fn rope_mut(&mut self) -> &mut TextRope

Accesses the underlying balanced B-Tree TextRope mutably.

Source

pub fn line_count(&self) -> usize

Total number of lines in the buffer.

Source

pub fn total_char_count(&self) -> usize

Total number of characters in the buffer.

Source

pub fn total_byte_count(&self) -> usize

Total number of bytes in the buffer (excluding \n separators).

Source

pub fn total_text_byte_len(&self) -> usize

Total UTF-8 byte length of the serialized \n-joined document.

Source

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

Source

pub fn position_to_point(&self, pos: Position) -> Point

Computes the Tree-Sitter Point (byte column) for pos.

Source

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

Source

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.

Source

pub fn height(&self) -> usize

Tree height of the B-Tree rope.

Source

pub fn line(&self, idx: usize) -> Option<&str>

Returns a reference to the line at the specified 0-based index.

Source

pub fn line_mut(&mut self, idx: usize) -> Option<&mut String>

Returns a mutable reference to the line at the specified 0-based index.

Source

pub fn line_len(&self, idx: usize) -> usize

Returns the character length of the line at the specified index.

Source

pub fn line_char_count(&self, idx: usize) -> usize

Returns the character count of the line at the specified index.

Source

pub fn line_byte_len(&self, idx: usize) -> usize

Returns the byte length of the line at the specified index.

Source

pub fn insert_char(&mut self, line: usize, col: usize, ch: char)

Inserts a character at the specified line and character column.

Source

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.

Source

pub fn split_line(&mut self, line: usize, col: usize)

Splits a line into two lines at the given character column index.

Source

pub fn join_line_with_next(&mut self, line: usize)

Joins the specified line with the subsequent line.

Source

pub fn delete_backwards( &mut self, line: usize, col: usize, ) -> Option<(usize, usize)>

Deletes a character before the specified position (backspace).

Source

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.

Source

pub fn slice_lines(&self, start: usize, count: usize) -> Vec<(usize, &str)>

Returns a slice of lines for virtual viewport rendering in logarithmic time.

Source

pub fn to_text(&self) -> String

Serializes entire buffer back into a single newline-separated String.

Trait Implementations§

Source§

impl Clone for LineBuffer

Source§

fn clone(&self) -> Self

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 Debug for LineBuffer

Source§

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

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

impl Default for LineBuffer

Source§

fn default() -> Self

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

impl Display for LineBuffer

Source§

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

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

impl Eq for LineBuffer

Source§

impl FromStr for LineBuffer

Source§

type Err = !

The associated error which can be returned from parsing.
Source§

fn from_str(text: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl PartialEq for LineBuffer

Source§

fn eq(&self, other: &Self) -> 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 LineBuffer

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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> IntoInitialState<T> for T

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,