Expand description
Read-only Vim cursor and viewport motion.
This module owns the coordinate types and pure movement vocabulary used by
both direct callers and the crate’s optional editable buffer. apply
borrows a logical line snapshot, clamps the supplied Cursor to a valid
UTF-8 boundary, applies one completed Motion, and updates Viewport
so the result remains visible. It never changes the input text.
§Coordinates
Cursor::byte_column is a zero-based UTF-8 byte offset, not a character
index or screen column. Viewport::left and Viewport::width are
terminal display cells. A tab advances to the next four-cell tab stop;
wide and combining Unicode characters use their terminal widths. Empty
input and empty lines have the single valid cursor position (line, 0).
Count parsing, incomplete commands, and character-search repetition belong
to crate::command. Text mutation and Insert-mode cursor rules belong to
crate::editor. Search histories, marks, jump lists, terminal keys, and
application resources remain caller-owned.
§Example
use vim_navigation::motion::{Cursor, Motion, MotionKind, Viewport, apply};
let lines = ["\t界"];
let mut viewport = Viewport::new(0, 0, 1, 8, 0);
let cursor = apply(
&lines,
Cursor::new(99, 2), // invalid line and inside the three-byte `界`
&mut viewport,
Motion::new(MotionKind::LineEnd),
);
assert_eq!(cursor, Cursor::new(0, 1));Structs§
- Cursor
- A zero-based text position whose column is a UTF-8 byte offset.
- Motion
- A completed Vim movement with its count and optional character argument.
- Viewport
- The visible part of a text pane, including any rendered gutter columns.
Enums§
- Count
Source - Origin of a motion count, including the semantically distinct implicit one.
- Motion
Kind - Vim’s standalone cursor and viewport movement vocabulary.