pub struct TextAreaState {
pub lines: Vec<String>,
pub cursor_line: usize,
pub cursor_col: usize,
pub scroll_y: usize,
pub scroll_x: usize,
pub visible_height: usize,
pub focused: bool,
pub enabled: bool,
pub tab_config: TabConfig,
}Expand description
State for a multi-line text area.
Fields§
§lines: Vec<String>Lines of text.
cursor_line: usizeCurrent line (0-indexed).
cursor_col: usizeCursor column (character index within line).
scroll_y: usizeVertical scroll offset.
scroll_x: usizeHorizontal scroll offset (for no-wrap mode).
visible_height: usizeVisible viewport height (set during render).
focused: boolWhether the textarea has focus.
enabled: boolWhether the textarea is enabled.
tab_config: TabConfigTab configuration.
Implementations§
Source§impl TextAreaState
impl TextAreaState
Sourcepub fn new(text: impl Into<String>) -> Self
pub fn new(text: impl Into<String>) -> Self
Create a new textarea state with initial text.
Cursor is positioned at the start of the text.
Sourcepub fn with_tab_config(self, config: TabConfig) -> Self
pub fn with_tab_config(self, config: TabConfig) -> Self
Set the tab configuration.
Sourcepub fn insert_char(&mut self, c: char)
pub fn insert_char(&mut self, c: char)
Insert a character at cursor position.
Sourcepub fn insert_str(&mut self, s: &str)
pub fn insert_str(&mut self, s: &str)
Insert a string at cursor position (handles multi-line input).
Sourcepub fn insert_newline(&mut self)
pub fn insert_newline(&mut self)
Insert a newline at cursor position.
Sourcepub fn insert_tab(&mut self)
pub fn insert_tab(&mut self)
Insert a tab (spaces or literal depending on config).
Sourcepub fn delete_char_backward(&mut self) -> bool
pub fn delete_char_backward(&mut self) -> bool
Delete character before cursor (backspace).
At the start of a line, merges with previous line.
Returns true if any change was made.
Sourcepub fn delete_char_forward(&mut self) -> bool
pub fn delete_char_forward(&mut self) -> bool
Delete character at cursor (delete key).
At the end of a line, merges with next line.
Returns true if any change was made.
Sourcepub fn delete_word_backward(&mut self) -> bool
pub fn delete_word_backward(&mut self) -> bool
Delete word before cursor.
Returns true if any characters were deleted.
Sourcepub fn delete_line(&mut self)
pub fn delete_line(&mut self)
Delete entire current line.
If there’s only one line, clears it instead.
Sourcepub fn delete_to_line_start(&mut self)
pub fn delete_to_line_start(&mut self)
Delete from cursor to line start (Ctrl+U).
Sourcepub fn delete_to_line_end(&mut self)
pub fn delete_to_line_end(&mut self)
Delete from cursor to line end (Ctrl+K).
Sourcepub fn move_left(&mut self)
pub fn move_left(&mut self)
Move cursor left by one character.
At the start of a line, moves to end of previous line.
Sourcepub fn move_right(&mut self)
pub fn move_right(&mut self)
Move cursor right by one character.
At the end of a line, moves to start of next line.
Sourcepub fn move_line_start(&mut self)
pub fn move_line_start(&mut self)
Move cursor to start of line (Home).
Sourcepub fn move_line_end(&mut self)
pub fn move_line_end(&mut self)
Move cursor to end of line (End).
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_page_up(&mut self)
pub fn move_page_up(&mut self)
Move cursor up by one page.
Sourcepub fn move_page_down(&mut self)
pub fn move_page_down(&mut self)
Move cursor down by one page.
Sourcepub fn move_to_start(&mut self)
pub fn move_to_start(&mut self)
Move cursor to start of document (Ctrl+Home).
Sourcepub fn move_to_end(&mut self)
pub fn move_to_end(&mut self)
Move cursor to end of document (Ctrl+End).
Sourcepub fn scroll_to_cursor(&mut self)
pub fn scroll_to_cursor(&mut self)
Scroll to make cursor visible.
Sourcepub fn ensure_cursor_visible(&mut self)
pub fn ensure_cursor_visible(&mut self)
Ensure cursor is visible (alias for scroll_to_cursor).
Sourcepub fn scroll_down(&mut self)
pub fn scroll_down(&mut self)
Scroll down by one line.
Sourcepub fn scroll_left(&mut self)
pub fn scroll_left(&mut self)
Scroll left (for no-wrap mode).
Sourcepub fn scroll_right(&mut self)
pub fn scroll_right(&mut self)
Scroll right (for no-wrap mode).
Sourcepub fn line_count(&self) -> usize
pub fn line_count(&self) -> usize
Get number of lines.
Sourcepub fn current_line(&self) -> &str
pub fn current_line(&self) -> &str
Get current line content.
Sourcepub fn text_before_cursor(&self) -> &str
pub fn text_before_cursor(&self) -> &str
Get text before cursor on current line.
Sourcepub fn text_after_cursor(&self) -> &str
pub fn text_after_cursor(&self) -> &str
Get text after cursor on current line.
Trait Implementations§
Source§impl Clone for TextAreaState
impl Clone for TextAreaState
Source§fn clone(&self) -> TextAreaState
fn clone(&self) -> TextAreaState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TextAreaState
impl Debug for TextAreaState
Auto Trait Implementations§
impl Freeze for TextAreaState
impl RefUnwindSafe for TextAreaState
impl Send for TextAreaState
impl Sync for TextAreaState
impl Unpin for TextAreaState
impl UnwindSafe for TextAreaState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more