pub struct TextBuffer { /* private fields */ }Expand description
A text buffer backed by a rope data structure for efficient editing.
Provides line-oriented access and editing operations suitable for
building a text editor widget. All positions are expressed as
(line, col) pairs using zero-based indexing.
Implementations§
Source§impl TextBuffer
impl TextBuffer
Sourcepub fn line_count(&self) -> usize
pub fn line_count(&self) -> usize
Return the number of lines in the buffer.
An empty buffer has 1 line. A buffer ending with a newline has an extra empty line at the end.
Sourcepub fn line(&self, idx: usize) -> Option<String>
pub fn line(&self, idx: usize) -> Option<String>
Get the content of a line by index (without trailing newline).
Returns None if the index is out of bounds.
Sourcepub fn line_len(&self, idx: usize) -> Option<usize>
pub fn line_len(&self, idx: usize) -> Option<usize>
Get the character count of a line (excluding trailing newline).
Returns None if the index is out of bounds.
Sourcepub fn total_chars(&self) -> usize
pub fn total_chars(&self) -> usize
Return the total number of characters in the buffer.
Sourcepub fn insert_char(&mut self, line: usize, col: usize, ch: char)
pub fn insert_char(&mut self, line: usize, col: usize, ch: char)
Insert a character at the given (line, col) position.
If the position is beyond the end of a line, the character is appended at the end of that line.
Sourcepub fn insert_str(&mut self, line: usize, col: usize, text: &str)
pub fn insert_str(&mut self, line: usize, col: usize, text: &str)
Insert a string at the given (line, col) position.
The string may contain newlines, which will split the line.
Sourcepub fn delete_char(&mut self, line: usize, col: usize)
pub fn delete_char(&mut self, line: usize, col: usize)
Delete a single character at the given (line, col) position.
If the position is at the end of a line, the trailing newline is removed, joining this line with the next.
Trait Implementations§
Source§impl Clone for TextBuffer
impl Clone for TextBuffer
Source§fn clone(&self) -> TextBuffer
fn clone(&self) -> TextBuffer
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more