Raxol.UI.Components.Input.MultiLineInput.TextHelper (Raxol v2.0.1)

View Source

Text manipulation helper functions for MultiLineInput component.

Summary

Functions

Calculates new cursor position.

Deletes the current selection and returns the updated state.

Handles backspace when no selection exists.

Handles delete when no selection exists.

Inserts a character at the cursor position.

Replaces text in a range with new text.

Splits text into lines based on width and wrap mode.

Functions

calculate_new_position(state, arg)

@spec calculate_new_position(
  Raxol.UI.Components.Input.MultiLineInput.t(),
  {integer(), integer()}
) :: {integer(), integer()}

calculate_new_position(state, text, arg)

@spec calculate_new_position(
  Raxol.UI.Components.Input.MultiLineInput.t(),
  String.t(),
  {integer(), integer()}
) :: {integer(), integer()}

Calculates new cursor position.

Can be used for:

  • Calculating position after text changes (2 args)
  • Calculating position after text insertion (3 args)

delete_selection(state)

Deletes the current selection and returns the updated state.

handle_backspace_no_selection(state)

Handles backspace when no selection exists.

handle_delete_no_selection(state)

Handles delete when no selection exists.

insert_char(state, char_codepoint)

Inserts a character at the cursor position.

replace_text_range(state, start_pos, end_pos, replacement_text)

Replaces text in a range with new text.

split_into_lines(text, width, wrap_mode)

@spec split_into_lines(String.t(), integer(), :none | :char | :word) :: [String.t()]

Splits text into lines based on width and wrap mode.