moveToLineBoundary function

SelectionRange moveToLineBoundary(
  1. EditorState state,
  2. SelectionRange start,
  3. bool forward, {
  4. bool includeWrap = false,
})

Move to the start or end of a line.

When includeWrap is true and the editor has line wrapping enabled, this moves to the visual line boundary instead of the logical line.

Implementation

SelectionRange moveToLineBoundary(
  EditorState state,
  SelectionRange start,
  bool forward, {
  bool includeWrap = false,
}) {
  final line = state.doc.lineAt(start.head);

  // For now, we just move to logical line boundaries
  // Visual line boundaries require view/layout information
  return EditorSelection.cursor(
    forward ? line.to : line.from,
    assoc: forward ? -1 : 1,
  );
}