Skip to main content

TextEditState

Struct TextEditState 

Source
pub struct TextEditState {
    pub text: String,
    pub cursor_pos: usize,
    pub selection_anchor: Option<usize>,
    pub scroll_offset: f32,
    pub scroll_offset_y: f32,
    pub cursor_blink_timer: f64,
    pub last_click_time: f64,
    pub last_click_element: u32,
    pub preferred_col: Option<usize>,
    pub no_styles_movement: bool,
    pub undo_stack: Vec<UndoEntry>,
    pub redo_stack: Vec<UndoEntry>,
}
Expand description

Persistent text editing state per text input element. Keyed by element u32 ID in PlyContext::text_edit_states.

Fields§

§text: String

The current text content.

§cursor_pos: usize

Character index of the cursor (0 = before first char, text.chars().count() = after last).

§selection_anchor: Option<usize>

When Some, defines the anchor of a selection range (anchor..cursor_pos or cursor_pos..anchor).

§scroll_offset: f32

Horizontal scroll offset (pixels) when text overflows the bounding box.

§scroll_offset_y: f32

Vertical scroll offset (pixels) for multiline text inputs.

§cursor_blink_timer: f64

Timer for cursor blink animation (seconds).

§last_click_time: f64

Timestamp of last click (for double-click detection).

§last_click_element: u32

Element ID of last click (for double-click detection).

§preferred_col: Option<usize>

Saved visual column for vertical (up/down) navigation. When set, up/down arrows try to return to this column.

§no_styles_movement: bool

When true, cursor movement skips structural style positions (} and empty content markers). Set from TextInputConfig::no_styles_movement.

§undo_stack: Vec<UndoEntry>

Undo stack: previous states (newest at end).

§redo_stack: Vec<UndoEntry>

Redo stack: states undone (newest at end).

Implementations§

Source§

impl TextEditState

Source

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

Returns the ordered selection range (start, end) if a selection is active.

Source

pub fn selected_text(&self) -> &str

Returns the selected text, or empty string if no selection.

Source

pub fn delete_selection(&mut self) -> bool

Delete the current selection and place cursor at the start. Returns true if a selection was deleted.

Source

pub fn insert_text(&mut self, s: &str, max_length: Option<usize>)

Insert text at the current cursor position, replacing any selection. Respects max_length if provided.

Source

pub fn move_left(&mut self, shift: bool)

Move cursor left by one character.

Source

pub fn move_right(&mut self, shift: bool)

Move cursor right by one character.

Source

pub fn move_word_left(&mut self, shift: bool)

Move cursor to the start of the previous word.

Source

pub fn move_word_right(&mut self, shift: bool)

Move cursor to the end of the next word.

Source

pub fn move_home(&mut self, shift: bool)

Move cursor to start of line.

Source

pub fn move_end(&mut self, shift: bool)

Move cursor to end of line.

Source

pub fn select_all(&mut self)

Select all text.

Source

pub fn backspace(&mut self)

Delete character before cursor (Backspace).

Source

pub fn delete_forward(&mut self)

Delete character after cursor (Delete key).

Source

pub fn backspace_word(&mut self)

Delete the word before the cursor (Ctrl+Backspace).

Source

pub fn delete_word_forward(&mut self)

Delete the word after the cursor (Ctrl+Delete).

Source

pub fn click_to_cursor( &mut self, click_x: f32, char_x_positions: &[f32], shift: bool, )

Set cursor position from a click at pixel x within the element. char_x_positions should be a sorted list of x-positions for each character boundary (index 0 = left edge of first char, index n = right edge of last char).

Source

pub fn select_word_at(&mut self, char_pos: usize)

Select the word at the given character position (for double-click).

Reset blink timer so cursor is immediately visible.

Source

pub fn cursor_visible(&self) -> bool

Returns whether the cursor should be visible based on blink timer.

Source

pub fn ensure_cursor_visible(&mut self, cursor_x: f32, visible_width: f32)

Update scroll offset to ensure cursor is visible within visible_width. cursor_x is the pixel x-position of the cursor relative to text start.

Source

pub fn ensure_cursor_visible_vertical( &mut self, cursor_line: usize, line_height: f32, visible_height: f32, )

Update vertical scroll offset to keep cursor visible in multiline mode. cursor_line is the 0-based line index the cursor is on. line_height is pixel height per line. visible_height is the element height.

Source

pub fn push_undo(&mut self, kind: UndoActionKind)

Push the current state onto the undo stack before an edit. kind controls grouping: consecutive edits of the same kind are merged (only InsertChar, Backspace, and Delete are grouped).

Source

pub fn undo(&mut self) -> bool

Undo the last edit. Returns true if undo was performed.

Source

pub fn redo(&mut self) -> bool

Redo the last undone edit. Returns true if redo was performed.

Source

pub fn move_line_home(&mut self, shift: bool)

Move cursor to the start of the current line (Home in multiline mode).

Source

pub fn move_line_end(&mut self, shift: bool)

Move cursor to the end of the current line (End in multiline mode).

Source

pub fn move_up(&mut self, shift: bool)

Move cursor up one line (multiline only).

Source

pub fn move_down(&mut self, shift: bool)

Move cursor down one line (multiline only).

Trait Implementations§

Source§

impl Clone for TextEditState

Source§

fn clone(&self) -> TextEditState

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 TextEditState

Source§

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

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

impl Default for TextEditState

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

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> NoneValue for T
where T: Default,

Source§

type NoneType = T

Source§

fn null_value() -> T

The none-equivalent value.
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> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more