pub struct CursorState {
pub position: CursorPosition,
pub selection: Option<Selection>,
pub preferred_col: Option<usize>,
}Expand description
The full cursor state for a text editing session.
Tracks the cursor position, optional selection, and the preferred column for vertical movement (so moving up/down through short lines returns to the original column).
Fields§
§position: CursorPositionCurrent cursor position.
selection: Option<Selection>Active selection, if any.
preferred_col: Option<usize>Preferred column for vertical movement.
Implementations§
Source§impl CursorState
impl CursorState
Sourcepub fn move_left(&mut self, buffer: &TextBuffer)
pub fn move_left(&mut self, buffer: &TextBuffer)
Move cursor left by one character, wrapping to the previous line.
Sourcepub fn move_right(&mut self, buffer: &TextBuffer)
pub fn move_right(&mut self, buffer: &TextBuffer)
Move cursor right by one character, wrapping to the next line.
Sourcepub fn move_up(&mut self, buffer: &TextBuffer)
pub fn move_up(&mut self, buffer: &TextBuffer)
Move cursor up by one line, preserving the preferred column.
Sourcepub fn move_down(&mut self, buffer: &TextBuffer)
pub fn move_down(&mut self, buffer: &TextBuffer)
Move cursor down by one line, preserving the preferred column.
Sourcepub fn move_to_line_start(&mut self)
pub fn move_to_line_start(&mut self)
Move cursor to the start of the current line.
Sourcepub fn move_to_line_end(&mut self, buffer: &TextBuffer)
pub fn move_to_line_end(&mut self, buffer: &TextBuffer)
Move cursor to the end of the current line.
Sourcepub fn move_to_buffer_start(&mut self)
pub fn move_to_buffer_start(&mut self)
Move cursor to the beginning of the buffer.
Sourcepub fn move_to_buffer_end(&mut self, buffer: &TextBuffer)
pub fn move_to_buffer_end(&mut self, buffer: &TextBuffer)
Move cursor to the end of the buffer.
Sourcepub fn start_selection(&mut self)
pub fn start_selection(&mut self)
Start a selection at the current cursor position.
Sourcepub fn extend_selection(&mut self)
pub fn extend_selection(&mut self)
Extend the selection to the current cursor position.
If no selection exists, this starts one from the current position.
Sourcepub fn clear_selection(&mut self)
pub fn clear_selection(&mut self)
Clear the current selection.
Sourcepub fn selected_text(&self, buffer: &TextBuffer) -> Option<String>
pub fn selected_text(&self, buffer: &TextBuffer) -> Option<String>
Get the text currently selected in the buffer.
Returns None if there is no selection or the selection is empty.
Trait Implementations§
Source§impl Clone for CursorState
impl Clone for CursorState
Source§fn clone(&self) -> CursorState
fn clone(&self) -> CursorState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more