Skip to main content

shift_fold

Function shift_fold 

Source
pub fn shift_fold(
    fold: Fold,
    edit_start: usize,
    drop_end: usize,
    shift_threshold: usize,
    delta: isize,
) -> Option<Fold>
Expand description

Shift a single fold’s start_row / end_row by an edit’s row-delta band. Returns None when the edit’s deleted band fully consumes the fold.

Each endpoint is mapped independently through the same drop/shift rule crate::buffer::View::rebase_marks applies to a point mark. Mapping the two endpoints independently is what produces the vim-shaped “edit inside a fold” semantics for free:

  • Both endpoints below shift_threshold and outside the deleted band → fold untouched (edit happened entirely outside the fold).
  • start_row outside the deleted band but end_row inside it → the edit deleted the fold’s tail; it clips to end at the last surviving row (edit_start - 1).
  • start_row inside the deleted band but end_row outside it → the edit deleted the fold’s head; it clips to start at edit_start (the row the surviving tail now occupies).
  • Both endpoints inside the deleted band → the edit consumed the whole fold; it’s dropped.
  • start_row below the threshold and end_row at/above it (an insert or a deletion landing strictly inside the fold) → start_row stays, end_row shifts by delta: the fold grows (insert) or shrinks (delete) around the edit, matching vim.
  • Both endpoints at/above the threshold → the fold shifts wholesale.