Skip to main content

TextInputState

Struct TextInputState 

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

The current text value.

§cursor: usize

Cursor position (character index).

§selection_anchor: Option<usize>

Selection anchor (where selection started). None = no selection.

Implementations§

Source§

impl TextInputState

Source

pub fn new() -> Self

Create a new empty state.

Source

pub fn with_value(value: impl Into<String>) -> Self

Create a new state with initial value.

Source

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

Insert a character at the cursor position. If there’s a selection, it’s deleted first.

Source

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

Insert a string at the cursor position. If there’s a selection, it’s deleted first.

Source

pub fn backspace(&mut self) -> bool

Delete the character before the cursor (backspace). If there’s a selection, deletes the selection instead.

Source

pub fn delete(&mut self) -> bool

Delete the character at the cursor position (delete). If there’s a selection, deletes the selection instead.

Source

pub fn move_left(&mut self) -> bool

Move cursor left (clears selection).

Source

pub fn move_right(&mut self) -> bool

Move cursor right (clears selection).

Source

pub fn move_home(&mut self)

Move cursor to the start (clears selection).

Source

pub fn move_end(&mut self)

Move cursor to the end (clears selection).

Source

pub fn clear(&mut self)

Clear the input.

Source

pub fn set_value(&mut self, value: impl Into<String>)

Set the value and move cursor to end.

Source

pub fn value(&self) -> &str

Get the current value.

Source

pub fn is_empty(&self) -> bool

Check if the input is empty.

Source

pub fn has_selection(&self) -> bool

Check if there’s an active selection.

Source

pub fn selection_range(&self) -> Option<(usize, usize)>

Get selection range (start, end) where start <= end.

Source

pub fn selected_text(&self) -> Option<&str>

Get the selected text.

Source

pub fn clear_selection(&mut self)

Clear the selection without deleting text.

Source

pub fn delete_selection(&mut self) -> Option<String>

Delete the selected text and return it.

Source

pub fn select_all(&mut self)

Select all text.

Source

pub fn select_left(&mut self) -> bool

Move cursor left with selection (shift+left).

Source

pub fn select_right(&mut self) -> bool

Move cursor right with selection (shift+right).

Source

pub fn select_to_home(&mut self)

Select to beginning (shift+home).

Source

pub fn select_to_end(&mut self)

Select to end (shift+end).

Source

pub fn to_props(&self) -> TextInputProps

Convert to props for rendering.

Trait Implementations§

Source§

impl Clone for TextInputState

Source§

fn clone(&self) -> TextInputState

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 TextInputState

Source§

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

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

impl Default for TextInputState

Source§

fn default() -> TextInputState

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> 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.