Skip to main content

Module text

Module text 

Source
Expand description

Shared text position types and helpers used by the buffer.

This module is intentionally “rope-agnostic” (it operates on indices and provides conversions given line-start information), so it can be reused whether the backing store is a Rope, a gap buffer, etc.

When used with ropey::Rope, you typically pair these helpers with:

  • Rope::len_chars()
  • Rope::line_to_char(line)
  • Rope::char_to_line(char_idx)
  • Rope::line(line).len_chars() (includes newline if present)

Structs§

CharIdx
A 0-based character index (Unicode scalar value index).
CharRange
A half-open character range: [start, end).
ColIdx
A 0-based column index in characters within a line.
GoalCol
A small helper for “preferred column” behavior (vim-like vertical motion).
LineCol
A (line, column) location in the buffer.
LineIdx
A 0-based line index.

Functions§

apply_goal_col
Updates (actual_col, goal_col) when moving vertically.
char_to_line_col
Computes a (line, col) for a given char_idx using a provided line_to_char function.
clamp_char
Clamps a char index into [0, len_chars].
clamp_col_to_line
Given a line length in chars, clamp a goal column to the line.
clamp_cursor_to_line_editable
Clamp a cursor char index into the editable bounds of its line.
clamp_range
Normalizes and clamps a range into [0, len_chars].
line_col_to_char
Computes a char index for a given (line, col) using a provided line_to_char function and a line_len_chars function.
line_editable_bounds
Computes the common “cursor line start” and “cursor line end” bounds.
line_len_without_newline
Computes a safe “visual” line length in chars, excluding a trailing \n if present (common for ropey lines).
move_char_clamped
Compute the next/prev character index with clamping.
ordered_pair
Returns (min, max) ordering of two char indices.