pub struct LineBuffer { /* private fields */ }Expand description
Text buffer with cursor tracking for line editing operations.
Manages the actual text being edited and the cursor position within it. Supports UTF-8 text and provides methods for character/word manipulation.
This struct is typically not used directly - instead use LineEditor which
provides the high-level editing interface.
Implementations§
Source§impl LineBuffer
impl LineBuffer
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the length of the buffer in bytes.
Note: For UTF-8 text, this is the byte count, not the character count.
Sourcepub fn cursor_pos(&self) -> usize
pub fn cursor_pos(&self) -> usize
Returns the current cursor position in bytes from the start.
Sourcepub fn as_str(&self) -> Result<&str>
pub fn as_str(&self) -> Result<&str>
Returns the buffer contents as a UTF-8 string slice.
§Errors
Returns Err if the buffer contains invalid UTF-8.
Sourcepub fn insert_char(&mut self, c: char)
pub fn insert_char(&mut self, c: char)
Inserts a character at the cursor position, moving the cursor forward.
Supports UTF-8 characters. The cursor advances by the byte length of the character.
Sourcepub fn delete_before_cursor(&mut self) -> bool
pub fn delete_before_cursor(&mut self) -> bool
Deletes the character before the cursor (backspace operation).
Returns true if a character was deleted, false if the cursor is at the start.
Sourcepub fn delete_at_cursor(&mut self) -> bool
pub fn delete_at_cursor(&mut self) -> bool
Deletes the character at the cursor (delete key operation).
Returns true if a character was deleted, false if the cursor is at the end.
Sourcepub fn move_cursor_left(&mut self) -> bool
pub fn move_cursor_left(&mut self) -> bool
Moves the cursor one position to the left.
Returns true if the cursor moved, false if already at the start.
Sourcepub fn move_cursor_right(&mut self) -> bool
pub fn move_cursor_right(&mut self) -> bool
Moves the cursor one position to the right.
Returns true if the cursor moved, false if already at the end.
Sourcepub fn move_cursor_to_start(&mut self) -> usize
pub fn move_cursor_to_start(&mut self) -> usize
Moves the cursor to the start of the line.
Returns the number of positions the cursor moved.
Sourcepub fn move_cursor_to_end(&mut self) -> usize
pub fn move_cursor_to_end(&mut self) -> usize
Moves the cursor to the end of the line.
Returns the number of positions the cursor moved.
Sourcepub fn move_cursor_word_left(&mut self) -> usize
pub fn move_cursor_word_left(&mut self) -> usize
Moves the cursor to the start of the previous word.
Words are defined as sequences of alphanumeric characters and underscores.
Symbols (like +, -, *) are treated as separate words. Only whitespace
is skipped when navigating between words.
Returns the number of positions the cursor moved.
Sourcepub fn move_cursor_word_right(&mut self) -> usize
pub fn move_cursor_word_right(&mut self) -> usize
Moves the cursor to the start of the next word.
Words are defined as sequences of alphanumeric characters and underscores.
Symbols (like +, -, *) are treated as separate words. Only whitespace
is skipped when navigating between words.
Returns the number of positions the cursor moved.
Sourcepub fn delete_word_left(&mut self) -> usize
pub fn delete_word_left(&mut self) -> usize
Deletes the word to the left of the cursor (Alt+Backspace operation).
Returns the number of bytes deleted.
Sourcepub fn delete_word_right(&mut self) -> usize
pub fn delete_word_right(&mut self) -> usize
Deletes the word to the right of the cursor (Ctrl+Delete operation).
Returns the number of bytes deleted.