pub struct Editor { /* private fields */ }Expand description
Core text editor combining Rope storage with cursor management.
Provides insert/delete/move operations with grapheme-aware cursor handling, undo/redo, and selection support. Cursor is always kept in valid bounds.
Implementations§
Source§impl Editor
impl Editor
Sourcepub fn with_text(text: &str) -> Self
pub fn with_text(text: &str) -> Self
Create an editor with initial text. Cursor starts at the end.
Sourcepub fn set_max_history(&mut self, max: usize)
pub fn set_max_history(&mut self, max: usize)
Set the maximum undo history depth.
Sourcepub fn set_max_undo_size(&mut self, bytes: usize)
pub fn set_max_undo_size(&mut self, bytes: usize)
Set the maximum undo history size in bytes.
Sourcepub fn cursor(&self) -> CursorPosition
pub fn cursor(&self) -> CursorPosition
Get the current cursor position.
Sourcepub fn set_cursor(&mut self, pos: CursorPosition)
pub fn set_cursor(&mut self, pos: CursorPosition)
Set cursor position (will be clamped to valid bounds). Clears selection.
Sourcepub fn line_count(&self) -> usize
pub fn line_count(&self) -> usize
Number of lines in the buffer.
Sourcepub fn line_text(&self, line: usize) -> Option<String>
pub fn line_text(&self, line: usize) -> Option<String>
Get the text of a specific line (without trailing newline).
Sourcepub fn insert_char(&mut self, ch: char)
pub fn insert_char(&mut self, ch: char)
Insert a single character at the cursor position.
Sourcepub fn insert_text(&mut self, text: &str)
pub fn insert_text(&mut self, text: &str)
Insert text at the cursor position. Deletes selection first if active.
Control characters (except newline and tab) are stripped to prevent terminal corruption.
Sourcepub fn insert_newline(&mut self)
pub fn insert_newline(&mut self)
Insert a newline at the cursor position.
Sourcepub fn delete_backward(&mut self) -> bool
pub fn delete_backward(&mut self) -> bool
Delete the character before the cursor (backspace). Deletes selection if active.
Returns true if a character was deleted.
Sourcepub fn delete_forward(&mut self) -> bool
pub fn delete_forward(&mut self) -> bool
Delete the character after the cursor (delete key). Deletes selection if active.
Returns true if a character was deleted.
Sourcepub fn delete_word_backward(&mut self) -> bool
pub fn delete_word_backward(&mut self) -> bool
Delete the word before the cursor (Ctrl+Backspace).
Returns true if any text was deleted.
Sourcepub fn delete_to_end_of_line(&mut self) -> bool
pub fn delete_to_end_of_line(&mut self) -> bool
Delete from cursor to end of line (Ctrl+K).
Returns true if any text was deleted.
Sourcepub fn move_right(&mut self)
pub fn move_right(&mut self)
Move cursor right by one grapheme.
Sourcepub fn move_word_left(&mut self)
pub fn move_word_left(&mut self)
Move cursor left by one word.
Sourcepub fn move_word_right(&mut self)
pub fn move_word_right(&mut self)
Move cursor right by one word.
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 move_to_document_start(&mut self)
pub fn move_to_document_start(&mut self)
Move cursor to start of document.
Sourcepub fn move_to_document_end(&mut self)
pub fn move_to_document_end(&mut self)
Move cursor to end of document.
Sourcepub fn select_left(&mut self)
pub fn select_left(&mut self)
Extend selection left by one grapheme.
Sourcepub fn select_right(&mut self)
pub fn select_right(&mut self)
Extend selection right by one grapheme.
Sourcepub fn select_down(&mut self)
pub fn select_down(&mut self)
Extend selection down one line.
Sourcepub fn select_word_left(&mut self)
pub fn select_word_left(&mut self)
Extend selection left by one word.
Sourcepub fn select_word_right(&mut self)
pub fn select_word_right(&mut self)
Extend selection right by one word.
Sourcepub fn select_all(&mut self)
pub fn select_all(&mut self)
Select all text.
Sourcepub fn clear_selection(&mut self)
pub fn clear_selection(&mut self)
Clear current selection without moving cursor.
Sourcepub fn selected_text(&self) -> Option<String>
pub fn selected_text(&self) -> Option<String>
Get selected text, if any non-empty selection exists.