pub struct TextInputState {
pub value: String,
pub cursor: usize,
pub selection_anchor: Option<usize>,
}Expand description
Helper struct for managing text input state.
This provides a convenient way to manage the value, cursor position, selection, and handle common editing operations.
Fields§
§value: StringThe current text value.
cursor: usizeCursor position (character index).
selection_anchor: Option<usize>Selection anchor (where selection started). None = no selection.
Implementations§
Source§impl TextInputState
impl TextInputState
Sourcepub fn with_value(value: impl Into<String>) -> Self
pub fn with_value(value: impl Into<String>) -> Self
Create a new state with initial value.
Sourcepub fn insert(&mut self, c: char)
pub fn insert(&mut self, c: char)
Insert a character at the cursor position. If there’s a selection, it’s deleted first.
Sourcepub fn insert_str(&mut self, s: &str)
pub fn insert_str(&mut self, s: &str)
Insert a string at the cursor position. If there’s a selection, it’s deleted first.
Sourcepub fn backspace(&mut self) -> bool
pub fn backspace(&mut self) -> bool
Delete the character before the cursor (backspace). If there’s a selection, deletes the selection instead.
Sourcepub fn delete(&mut self) -> bool
pub fn delete(&mut self) -> bool
Delete the character at the cursor position (delete). If there’s a selection, deletes the selection instead.
Sourcepub fn move_right(&mut self) -> bool
pub fn move_right(&mut self) -> bool
Move cursor right (clears selection).
Sourcepub fn has_selection(&self) -> bool
pub fn has_selection(&self) -> bool
Check if there’s an active selection.
Sourcepub fn selection_range(&self) -> Option<(usize, usize)>
pub fn selection_range(&self) -> Option<(usize, usize)>
Get selection range (start, end) where start <= end.
Sourcepub fn selected_text(&self) -> Option<&str>
pub fn selected_text(&self) -> Option<&str>
Get the selected text.
Sourcepub fn clear_selection(&mut self)
pub fn clear_selection(&mut self)
Clear the selection without deleting text.
Sourcepub fn delete_selection(&mut self) -> Option<String>
pub fn delete_selection(&mut self) -> Option<String>
Delete the selected text and return it.
Sourcepub fn select_all(&mut self)
pub fn select_all(&mut self)
Select all text.
Sourcepub fn select_left(&mut self) -> bool
pub fn select_left(&mut self) -> bool
Move cursor left with selection (shift+left).
Sourcepub fn select_right(&mut self) -> bool
pub fn select_right(&mut self) -> bool
Move cursor right with selection (shift+right).
Sourcepub fn select_to_home(&mut self)
pub fn select_to_home(&mut self)
Select to beginning (shift+home).
Sourcepub fn select_to_end(&mut self)
pub fn select_to_end(&mut self)
Select to end (shift+end).
Sourcepub fn to_props(&self) -> TextInputProps
pub fn to_props(&self) -> TextInputProps
Convert to props for rendering.
Trait Implementations§
Source§impl Clone for TextInputState
impl Clone for TextInputState
Source§fn clone(&self) -> TextInputState
fn clone(&self) -> TextInputState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more