Skip to main content

move_cursor_visual

Function move_cursor_visual 

Source
pub fn move_cursor_visual(
    geom: &TextGeometry,
    buf: &TextBuffer,
    cur: TextCursor,
    motion: CursorMotion,
) -> (TextPos, Option<f32>)
Expand description

D6: resolve a soft-wrap-aware vertical / line-bound motion against shaped TextGeometry. Returns (new head, new goal_x): the goal x to store back on the cursor (Qt verticalMovementX, D5).

  • LineUp / LineDown: step one visual line, landing on the byte whose caret x is nearest the sticky goal_x (seeded from the caret’s current x when goal_x is None); the goal is preserved across the move so a run of Up/Down tracks the original column. At the top / bottom visual line the motion delegates to the byte-only move_cursor (doc start / end), matching Qt.
  • LineStart / LineEnd: snap to the VISUAL line’s byte bounds (soft-wrap aware), clearing the goal like any horizontal motion.
  • Any other motion delegates to move_cursor and clears the goal.

No shaper dependency: the caller passes the geometry the producer already shaped. Falls back naturally when the geometry is empty (single logical line via move_cursor).