pub struct EditBuffer { /* private fields */ }Expand description
Text buffer with editing operations, cursor, and undo/redo.
EditBuffer is the primary type for text editing. It tracks cursor
position, maintains undo/redo history, and provides operations for:
- Cursor movement: Lines, words, characters, document bounds
- Text editing: Insert, delete, backspace with cursor tracking
- Line operations: Duplicate, move, delete lines
- History: Grouped undo/redo with configurable depth limit
§History Management
Edit operations are grouped automatically. Call commit
to force a group boundary (e.g., after a pause in typing). The history depth
is bounded (default 1000 groups) to limit memory usage.
Implementations§
Source§impl EditBuffer
impl EditBuffer
Sourcepub fn with_max_history_depth(max_depth: usize) -> Self
pub fn with_max_history_depth(max_depth: usize) -> Self
Create an edit buffer with a custom maximum undo history depth.
The default is 1000 undo groups. Set a lower value for memory-constrained environments or a higher value for documents that need extensive undo history.
Sourcepub fn set_max_history_depth(&mut self, max_depth: usize)
pub fn set_max_history_depth(&mut self, max_depth: usize)
Set the maximum undo history depth.
If the current history exceeds the new depth, oldest entries will be pruned on the next commit.
Sourcepub fn max_history_depth(&self) -> usize
pub fn max_history_depth(&self) -> usize
Get the current maximum undo history depth.
Sourcepub fn buffer(&self) -> &TextBuffer
pub fn buffer(&self) -> &TextBuffer
Get the underlying text buffer.
Sourcepub fn buffer_mut(&mut self) -> &mut TextBuffer
pub fn buffer_mut(&mut self) -> &mut TextBuffer
Get mutable access to the text buffer.
Sourcepub fn highlighted_buffer(&self) -> &HighlightedBuffer
pub fn highlighted_buffer(&self) -> &HighlightedBuffer
Get the highlighted buffer.
Sourcepub fn highlighted_buffer_mut(&mut self) -> &mut HighlightedBuffer
pub fn highlighted_buffer_mut(&mut self) -> &mut HighlightedBuffer
Get mutable access to the highlighted buffer.
Sourcepub fn set_cursor(&mut self, cursor: Cursor)
pub fn set_cursor(&mut self, cursor: Cursor)
Set the cursor position.
Sourcepub fn set_cursor_by_offset(&mut self, offset: usize)
pub fn set_cursor_by_offset(&mut self, offset: usize)
Set the cursor by character offset.
Sourcepub fn get_cursor_position(&self) -> CursorPosition
pub fn get_cursor_position(&self) -> CursorPosition
Get cursor position info.
Sourcepub fn move_right(&mut self)
pub fn move_right(&mut self)
Move cursor right.
Sourcepub fn move_to_line_start(&mut self)
pub fn move_to_line_start(&mut self)
Move cursor to start of line.
Sourcepub fn move_to_line_end(&mut self)
pub fn move_to_line_end(&mut self)
Move cursor to end of line.
Sourcepub fn delete_backward(&mut self)
pub fn delete_backward(&mut self)
Delete character before cursor.
Sourcepub fn delete_forward(&mut self)
pub fn delete_forward(&mut self)
Delete character after cursor.
Sourcepub fn delete_range(&mut self, start: Cursor, end: Cursor)
pub fn delete_range(&mut self, start: Cursor, end: Cursor)
Delete a range between two cursors.
Sourcepub fn delete_range_offsets(&mut self, start: usize, end: usize)
pub fn delete_range_offsets(&mut self, start: usize, end: usize)
Delete a range between character offsets.
Sourcepub fn delete_line(&mut self)
pub fn delete_line(&mut self)
Delete the current line (including trailing newline if present).
Sourcepub fn duplicate_line(&mut self)
pub fn duplicate_line(&mut self)
Duplicate the current line (insert copy below).
Sourcepub fn move_line_up(&mut self)
pub fn move_line_up(&mut self)
Move the current line up (swap with the line above).
Sourcepub fn move_line_down(&mut self)
pub fn move_line_down(&mut self)
Move the current line down (swap with the line below).
Sourcepub fn replace_text(&mut self, text: &str)
pub fn replace_text(&mut self, text: &str)
Replace the entire text, clearing history.
Sourcepub fn get_next_word_boundary(&self) -> usize
pub fn get_next_word_boundary(&self) -> usize
Get the next word boundary (character offset).
Sourcepub fn get_prev_word_boundary(&self) -> usize
pub fn get_prev_word_boundary(&self) -> usize
Get the previous word boundary (character offset).
Sourcepub fn move_word_right(&mut self)
pub fn move_word_right(&mut self)
Move cursor to the next word boundary.
Sourcepub fn move_word_left(&mut self)
pub fn move_word_left(&mut self)
Move cursor to the previous word boundary.
Sourcepub fn delete_word_forward(&mut self)
pub fn delete_word_forward(&mut self)
Delete from cursor to the next word boundary.
Sourcepub fn delete_word_backward(&mut self)
pub fn delete_word_backward(&mut self)
Delete from cursor to the previous word boundary.
Sourcepub fn clear_history(&mut self)
pub fn clear_history(&mut self)
Clear the undo/redo history.
This removes all undo and redo entries. Useful when loading new content where previous history is no longer relevant.