Skip to main content

TextAreaState

Struct TextAreaState 

Source
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: usize

Current line (0-indexed).

§cursor_col: usize

Cursor column (character index within line).

§scroll_y: usize

Vertical scroll offset.

§scroll_x: usize

Horizontal scroll offset (for no-wrap mode).

§visible_height: usize

Visible viewport height (set during render).

§focused: bool

Whether the textarea has focus.

§enabled: bool

Whether the textarea is enabled.

§tab_config: TabConfig

Tab configuration.

Implementations§

Source§

impl TextAreaState

Source

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.

Source

pub fn empty() -> Self

Create an empty textarea state.

Source

pub fn with_tab_config(self, config: TabConfig) -> Self

Set the tab configuration.

Source

pub fn insert_char(&mut self, c: char)

Insert a character at cursor position.

Source

pub fn insert_str(&mut self, s: &str)

Insert a string at cursor position (handles multi-line input).

Source

pub fn insert_newline(&mut self)

Insert a newline at cursor position.

Source

pub fn insert_tab(&mut self)

Insert a tab (spaces or literal depending on config).

Source

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.

Source

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.

Source

pub fn delete_word_backward(&mut self) -> bool

Delete word before cursor.

Returns true if any characters were deleted.

Source

pub fn delete_line(&mut self)

Delete entire current line.

If there’s only one line, clears it instead.

Source

pub fn delete_to_line_start(&mut self)

Delete from cursor to line start (Ctrl+U).

Source

pub fn delete_to_line_end(&mut self)

Delete from cursor to line end (Ctrl+K).

Source

pub fn move_left(&mut self)

Move cursor left by one character.

At the start of a line, moves to end of previous line.

Source

pub fn move_right(&mut self)

Move cursor right by one character.

At the end of a line, moves to start of next line.

Source

pub fn move_line_start(&mut self)

Move cursor to start of line (Home).

Source

pub fn move_line_end(&mut self)

Move cursor to end of line (End).

Source

pub fn move_word_left(&mut self)

Move cursor left by one word.

Source

pub fn move_word_right(&mut self)

Move cursor right by one word.

Source

pub fn move_up(&mut self)

Move cursor up by one line.

Source

pub fn move_down(&mut self)

Move cursor down by one line.

Source

pub fn move_page_up(&mut self)

Move cursor up by one page.

Source

pub fn move_page_down(&mut self)

Move cursor down by one page.

Source

pub fn move_to_start(&mut self)

Move cursor to start of document (Ctrl+Home).

Source

pub fn move_to_end(&mut self)

Move cursor to end of document (Ctrl+End).

Source

pub fn scroll_to_cursor(&mut self)

Scroll to make cursor visible.

Source

pub fn ensure_cursor_visible(&mut self)

Ensure cursor is visible (alias for scroll_to_cursor).

Source

pub fn scroll_up(&mut self)

Scroll up by one line.

Source

pub fn scroll_down(&mut self)

Scroll down by one line.

Source

pub fn scroll_left(&mut self)

Scroll left (for no-wrap mode).

Source

pub fn scroll_right(&mut self)

Scroll right (for no-wrap mode).

Source

pub fn text(&self) -> String

Get full text content (all lines joined with newlines).

Source

pub fn set_text(&mut self, text: impl Into<String>)

Set text content.

Cursor moves to the end.

Source

pub fn clear(&mut self)

Clear all text.

Source

pub fn line_count(&self) -> usize

Get number of lines.

Source

pub fn current_line(&self) -> &str

Get current line content.

Source

pub fn is_empty(&self) -> bool

Check if textarea is empty.

Source

pub fn len(&self) -> usize

Get total character count (including newlines).

Source

pub fn text_before_cursor(&self) -> &str

Get text before cursor on current line.

Source

pub fn text_after_cursor(&self) -> &str

Get text after cursor on current line.

Trait Implementations§

Source§

impl Clone for TextAreaState

Source§

fn clone(&self) -> TextAreaState

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TextAreaState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TextAreaState

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.