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: f32anim_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: f32Horizontal 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
impl TextEditState
Sourcepub fn cursor(&self) -> usize
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).
Sourcepub fn selection_range(&self) -> Option<(usize, usize)>
pub fn selection_range(&self) -> Option<(usize, usize)>
Normalized (start, end) char range, or None when the primary
selection is collapsed (no active selection).
pub fn can_undo(&self) -> bool
pub fn can_redo(&self) -> bool
Sourcepub fn with_selection(&self, selection: Selection, now: f32) -> TextEditState
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
impl Clone for TextEditState
Source§fn clone(&self) -> TextEditState
fn clone(&self) -> TextEditState
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more