Skip to main content

TextAreaState

Struct TextAreaState 

Source
pub struct TextAreaState { /* private fields */ }
Expand description

State for a TextArea component.

Implementations§

Source§

impl TextAreaState

Source

pub fn has_selection(&self) -> bool

Returns true if there is an active text selection.

Source

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

Returns the ordered selection positions as ((start_row, start_col), (end_row, end_col)).

Source

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

Returns the selected text, or None if no selection.

Source

pub fn clipboard(&self) -> &str

Returns the internal clipboard contents.

Source§

impl TextAreaState

Source

pub fn new() -> Self

Creates a new empty textarea.

§Example
use envision::component::TextAreaState;

let state = TextAreaState::new();
assert!(state.is_empty());
assert_eq!(state.line_count(), 1);
Source

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

Creates a textarea with initial content, split on newlines. Cursor is placed at the end of the content.

Source

pub fn with_placeholder(placeholder: impl Into<String>) -> Self

Creates a textarea with placeholder text.

Source

pub fn value(&self) -> String

Returns the full text content (lines joined with \n).

Source

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

Sets the content from a string (splits on \n). Cursor moves to end.

Source

pub fn cursor_position(&self) -> (usize, usize)

Returns the cursor position as (row, char_column).

Source

pub fn cursor_display_position(&self) -> (usize, usize)

Returns the cursor display position as (row, terminal_column_width).

Unlike cursor_position() which returns the character count for the column, this returns the display width accounting for wide characters (emoji, CJK) that occupy 2 terminal columns.

§Example
use envision::component::{TextArea, TextAreaState, TextAreaMessage, Component};

let mut state = TextArea::init();
TextArea::update(&mut state, TextAreaMessage::Insert('A'));
TextArea::update(&mut state, TextAreaMessage::Insert('\u{1F600}')); // emoji

// Character count is 2 (two characters)
assert_eq!(state.cursor_position(), (0, 2));
// Display width is 3 (A=1 + 😀=2)
assert_eq!(state.cursor_display_position(), (0, 3));
Source

pub fn cursor_row(&self) -> usize

Returns the cursor row.

Source

pub fn cursor_col(&self) -> usize

Returns the cursor column (byte offset).

Source

pub fn line_count(&self) -> usize

Returns the number of lines.

Source

pub fn line(&self, index: usize) -> Option<&str>

Returns a specific line by index.

Source

pub fn current_line(&self) -> &str

Returns the current line (at cursor row).

Source

pub fn is_empty(&self) -> bool

Returns true if the textarea is empty.

A textarea is empty if it contains only a single empty line.

Source

pub fn placeholder(&self) -> &str

Returns the placeholder text.

Source

pub fn set_placeholder(&mut self, placeholder: impl Into<String>)

Sets the placeholder text.

Source

pub fn scroll_offset(&self) -> usize

Returns the scroll offset.

Source

pub fn set_cursor_position(&mut self, row: usize, col: usize)

Sets the cursor position (row, char_column).

Both row and column are clamped to valid ranges.

Source

pub fn ensure_cursor_visible(&mut self, visible_lines: usize)

Ensures the cursor is visible within the viewport.

Source

pub fn can_undo(&self) -> bool

Returns true if there are edits that can be undone.

Source

pub fn can_redo(&self) -> bool

Returns true if there are edits that can be redone.

Source

pub fn is_focused(&self) -> bool

Returns true if the textarea is focused.

Source

pub fn set_focused(&mut self, focused: bool)

Sets the focus state.

Source

pub fn is_disabled(&self) -> bool

Returns true if the textarea is disabled.

Source

pub fn set_disabled(&mut self, disabled: bool)

Sets the disabled state.

Source

pub fn with_disabled(self, disabled: bool) -> Self

Sets the disabled state using builder pattern.

Source

pub fn handle_event(&self, event: &Event) -> Option<TextAreaMessage>

Maps an input event to a textarea message.

Source

pub fn dispatch_event(&mut self, event: &Event) -> Option<TextAreaOutput>

Dispatches an event, updating state and returning any output.

Source

pub fn update(&mut self, msg: TextAreaMessage) -> Option<TextAreaOutput>

Updates the textarea state with a message, returning any output.

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

impl<'de> Deserialize<'de> for TextAreaState

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for TextAreaState

Source§

fn eq(&self, other: &TextAreaState) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for TextAreaState

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for TextAreaState

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> StateExt for T

Source§

fn updated(self, cmd: Command<impl Clone>) -> UpdateResult<Self, impl Clone>

Updates self and returns a command.
Source§

fn unchanged(self) -> UpdateResult<Self, ()>

Returns self with no command.
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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,