Raxol. UI. Components. Input. TextEditing
(Raxol v2.6.0)
View Source
Shared text editing operations for input components.
Provides pure functions for insert, backspace, delete, and cursor
movement that operate on {value, cursor_pos} tuples. Components
map their own state structure to/from these tuples.
Summary
Functions
Deletes the character before the cursor (backspace).
Deletes the character at the cursor position (forward delete).
Inserts a character (or string) at the cursor position.
Moves the cursor by an offset, clamped to valid bounds.
Moves the cursor to an absolute position, clamped to valid bounds.
Types
@type cursor_pos() :: non_neg_integer()
Functions
@spec backspace(String.t(), cursor_pos()) :: {String.t(), cursor_pos()} | {:noop, cursor_pos()}
Deletes the character before the cursor (backspace).
Returns {new_value, new_cursor_pos}. No-op if cursor is at position 0.
@spec delete(String.t(), cursor_pos()) :: {String.t(), cursor_pos()} | {:noop, cursor_pos()}
Deletes the character at the cursor position (forward delete).
Returns {new_value, cursor_pos}. No-op if cursor is at end.
@spec insert_at(String.t(), cursor_pos(), String.t()) :: {String.t(), cursor_pos()}
Inserts a character (or string) at the cursor position.
Returns {new_value, new_cursor_pos}.
@spec move_cursor(String.t(), cursor_pos(), integer()) :: cursor_pos()
Moves the cursor by an offset, clamped to valid bounds.
Returns the new cursor position.
@spec move_cursor_to(String.t(), cursor_pos()) :: cursor_pos()
Moves the cursor to an absolute position, clamped to valid bounds.