Skip to main content

Module wrap

Module wrap 

Source
Expand description

Soft-wrap helpers shared between the renderer, viewport scroll, and the buffer’s vertical motion code.

Enums§

Wrap
Soft-wrap mode controlling how doc rows wider than the text area turn into multiple visual rows. Default is Wrap::None — every doc row is exactly one screen row and top_col clips the left side, mirroring vim’s set nowrap default for sqeel today.

Functions§

char_col_for_visual_offset
Inverse of the per-char accounting wrap_segments uses to find where a segment breaks: map a visual x offset (visual_offset, cells counted from the segment’s OWN left edge — i.e. 0 at seg.0, matching how the renderer paints each wrapped row starting at its text area’s left column regardless of seg.0) to the char index within seg = [start, end) it lands on.
segment_for_col
Returns the index into segments whose [start, end) covers col. The past-end cursor (col == last segment's end) maps to the last segment, matching vim’s “EOL on the visual row that holds the line’s last char” behaviour.
visual_offset_for_char_col
Forward companion to char_col_for_visual_offset: map a char column (within a segment starting at seg_start) to its visual x offset, in cells counted from the segment’s OWN left edge — the exact inverse relationship, using the same per-char width formula. char_col should be >= seg_start (typically chosen via segment_for_col first); a char_col before seg_start is treated as seg_start (offset 0).
wrap_segments
Split line into char-index segments [start, end) such that each segment’s display width fits within width cells. Wrap::Word rewinds to the last whitespace inside the candidate segment when a break would otherwise split a word; falls through to a char break for runs longer than width. Wrap::None is not expected here — callers branch before calling — but is handled for completeness as a single segment covering the full line.