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

cursor_pos()

@type cursor_pos() :: non_neg_integer()

Functions

backspace(value, cursor_pos)

@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.

delete(value, cursor_pos)

@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.

insert_at(value, cursor_pos, char)

@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}.

move_cursor(value, cursor_pos, offset)

@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.

move_cursor_to(value, pos)

@spec move_cursor_to(String.t(), cursor_pos()) :: cursor_pos()

Moves the cursor to an absolute position, clamped to valid bounds.