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: StringThe current text content.
cursor_pos: usizeCharacter 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: f32Horizontal scroll offset (pixels) when text overflows the bounding box.
scroll_offset_y: f32Vertical scroll offset (pixels) for multiline text inputs.
cursor_blink_timer: f64Timer for cursor blink animation (seconds).
last_click_time: f64Timestamp of last click (for double-click detection).
last_click_element: u32Element 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: boolWhen 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
impl TextEditState
Sourcepub fn selection_range(&self) -> Option<(usize, usize)>
pub fn selection_range(&self) -> Option<(usize, usize)>
Returns the ordered selection range (start, end) if a selection is active.
Sourcepub fn selected_text(&self) -> &str
pub fn selected_text(&self) -> &str
Returns the selected text, or empty string if no selection.
Sourcepub fn delete_selection(&mut self) -> bool
pub fn delete_selection(&mut self) -> bool
Delete the current selection and place cursor at the start. Returns true if a selection was deleted.
Sourcepub fn insert_text(&mut self, s: &str, max_length: Option<usize>)
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.
Sourcepub fn move_right(&mut self, shift: bool)
pub fn move_right(&mut self, shift: bool)
Move cursor right by one character.
Sourcepub fn move_word_left(&mut self, shift: bool)
pub fn move_word_left(&mut self, shift: bool)
Move cursor to the start of the previous word.
Sourcepub fn move_word_right(&mut self, shift: bool)
pub fn move_word_right(&mut self, shift: bool)
Move cursor to the end of the next word.
Sourcepub fn select_all(&mut self)
pub fn select_all(&mut self)
Select all text.
Sourcepub fn delete_forward(&mut self)
pub fn delete_forward(&mut self)
Delete character after cursor (Delete key).
Sourcepub fn backspace_word(&mut self)
pub fn backspace_word(&mut self)
Delete the word before the cursor (Ctrl+Backspace).
Sourcepub fn delete_word_forward(&mut self)
pub fn delete_word_forward(&mut self)
Delete the word after the cursor (Ctrl+Delete).
Sourcepub fn click_to_cursor(
&mut self,
click_x: f32,
char_x_positions: &[f32],
shift: bool,
)
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).
Sourcepub fn select_word_at(&mut self, char_pos: usize)
pub fn select_word_at(&mut self, char_pos: usize)
Select the word at the given character position (for double-click).
Sourcepub fn reset_blink(&mut self)
pub fn reset_blink(&mut self)
Reset blink timer so cursor is immediately visible.
Sourcepub fn cursor_visible(&self) -> bool
pub fn cursor_visible(&self) -> bool
Returns whether the cursor should be visible based on blink timer.
Sourcepub fn ensure_cursor_visible(&mut self, cursor_x: f32, visible_width: f32)
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.
Sourcepub fn ensure_cursor_visible_vertical(
&mut self,
cursor_line: usize,
line_height: f32,
visible_height: f32,
)
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.
Sourcepub fn push_undo(&mut self, kind: UndoActionKind)
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).
Sourcepub fn move_line_home(&mut self, shift: bool)
pub fn move_line_home(&mut self, shift: bool)
Move cursor to the start of the current line (Home in multiline mode).
Sourcepub fn move_line_end(&mut self, shift: bool)
pub fn move_line_end(&mut self, shift: bool)
Move cursor to the end of the current line (End in multiline mode).
Trait Implementations§
Source§impl Clone for TextEditState
impl Clone for TextEditState
Source§fn clone(&self) -> TextEditState
fn clone(&self) -> TextEditState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more