Skip to main content

TextEditState

Struct TextEditState 

Source
pub struct TextEditState {
    pub selection: Selection,
    pub last_edit_at: f32,
    pub scroll_x: f32,
    pub goal_x: Option<f32>,
    pub last_edit_range: Option<(usize, usize)>,
    pub ime_range: Option<(usize, usize)>,
    pub scrolled_cursor: Option<usize>,
    /* private fields */
}
Expand description

Persistent per-node editing state (D091): selection + undo/redo history, NOT the text value itself. The value stays app-owned, reported via EditableDecl::on_change — the same controlled-component convention every other stateful widget here uses (Slider, Switch, Checkbox). Survives a rebuild with the same value untouched — a widget rebuilding keeps its caret position and undo history.

Fields§

§selection: Selection§last_edit_at: f32

anim_clock() timestamp of the last edit/move — the caret blink resets to solid-on from this point, so typing/navigating always reads as responsive instead of possibly mid-blink-invisible.

§scroll_x: f32

Horizontal scroll-into-view offset (D116 Step 3) — how far the content is shifted left so the caret stays visible when the value overflows the field’s width. Persistent so it doesn’t reset to 0 every repaint; recomputed/clamped by the widget each paint against the current TextLayoutSnapshot.

§goal_x: Option<f32>

Goal-column memory for vertical caret movement across wrapped lines (D116 Step 4, TextArea) — the on-screen x the caret is “trying” to stay at while Up/Down walks through shorter lines, same convention every real editor uses. Set on the first vertical move from the caret’s actual x, reused unchanged by consecutive vertical moves, cleared by any horizontal move/edit/click (see moved/apply_and_record) so a fresh vertical move recomputes it.

§last_edit_range: Option<(usize, usize)>

The char range (in the NEW value’s coordinate space) touched by the most recent CONTENT edit — None after a pure movement/ selection change, or when nothing has been edited yet (D116 Step 5). This is what makes SpanSource incremental: the widget passes it straight through as the tokenizer’s changed_range argument instead of always re-scanning the whole document.

§ime_range: Option<(usize, usize)>

Char range currently occupied by an UNCOMMITTED IME preedit composition (D116 Step 6) — TextInput/TextArea render an underline decoration under it (the universal CJK-composition convention). Set/replaced by ime_set_preedit, cleared by ime_commit and by any other movement/edit (composing text is not something a click or Cmd+Z should have to know about).

§scrolled_cursor: Option<usize>

The caret position vertical scroll-into-view has already chased (TextArea) — VIEW state like scroll_x, written by the WIDGET during paint (via PaintCtx::set_scrolled_cursor), unlike every document/selection field above, which only the engine mutates. The widget chases the caret ONLY when cursor() differs from this, then records the new position. Without the gate the chase ran every focused frame and FOUGHT wheel input: a caret on a bottom line snapped every scroll-up straight back (live bug, 2026-07-12 — “no scrolling when the cursor is at the bottom”).

Implementations§

Source§

impl TextEditState

Source

pub fn cursor(&self) -> usize

The primary caret’s live position — sugar over .selection, kept for the common single-cursor read (rendering the caret glyph).

Source

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

Normalized (start, end) char range, or None when the primary selection is collapsed (no active selection).

Source

pub fn can_undo(&self) -> bool

Source

pub fn can_redo(&self) -> bool

Source

pub fn with_selection(&self, selection: Selection, now: f32) -> TextEditState

Set the selection directly, preserving undo/redo history — the primitive behind EditController::set_selection (a pure selection change is not an edit, so it must not touch the undo stack, but its private fields aren’t reachable via struct-update syntax from outside this module).

Trait Implementations§

Source§

impl Clone for TextEditState

Source§

fn clone(&self) -> TextEditState

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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
Source§

impl PartialEq for TextEditState

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for TextEditState

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.