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).
- Char
Range - 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 givenchar_idxusing a providedline_to_charfunction. - 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 providedline_to_charfunction and aline_len_charsfunction. - 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
\nif 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.