Skip to main content

Module position

Module position 

Source
Expand description

Position newtypes and the conversions between them.

This is the only module that knows about tab stops, grapheme clusters and display widths. The canonical position everywhere else is ByteOffset.

Structs§

ByteOffset
Byte offset into the document’s UTF-8 text, always on a char boundary.
CharIdx
Char index; only used at the boundary with Ropey 1.x.
LineCol
A line and a byte column within that line.
VisualCol
On-screen cell column, after tab expansion and wide-glyph widths.
Wrapped
How one line wraps into display rows.

Constants§

MIN_WRAP_WIDTH
The narrowest wrap width, in cells.

Functions§

byte_to_line_col
byte_to_visual_col
cells
(byte, visual column, width in cells) of each grapheme of one line’s text.
grapheme_width
Display width of one grapheme starting at visual column col. Tabs expand to the next tab stop; every other grapheme takes at least one cell so that distinct boundaries always have distinct visual columns.
line_col_to_byte
Clamps the column to the end of the line. The column must land on a char boundary; out-of-range lines clamp to the end of the document.
line_visual_width
Width of the whole line in visual columns.
next_grapheme_boundary
The next grapheme boundary after pos (or the end of the document).
prev_grapheme_boundary
The previous grapheme boundary before pos (or 0).
visual_col_to_byte
The last grapheme boundary on line whose visual column is <= col, or the line end if the line is shorter (no virtual space).
visual_col_to_byte_ceil
The first grapheme boundary on line whose visual column is >= col, or the line end. Used for the left edge of a rectangle so that a tab or wide glyph straddling the edge stays outside it.
wrap_line
Wraps text (one line, without its line break) to rows of width cells. Rows break after a run of whitespace when there is one in the row, otherwise before the grapheme that does not fit; a grapheme is never split, and one wider than a row gets a row of its own. Tab stops count from the start of the line, so wrapping never changes a grapheme’s visual column. Rows after the first are indented like the line, by at most half the width.