moveToLineStart function

NavigationResult moveToLineStart(
  1. Root root,
  2. CaretStop current, {
  3. List<LogicalLine>? lines,
})

Moves the cursor to the start of the current logical line. If lines is provided (e.g. from a document cache), it is used directly instead of rebuilding the entire tree with buildAllLogicalLines(root).

Implementation

NavigationResult moveToLineStart(
  Root root,
  CaretStop current, {
  List<LogicalLine>? lines,
}) {
  final lines_ = lines ?? buildAllLogicalLines(root);
  final lineInfo = findLineForStop(lines_, current);
  if (lineInfo == null) return NavigationResult.none;

  final line = lines_[lineInfo.lineIndex];
  if (line.stops.isEmpty) return NavigationResult.none;

  final firstStop = line.stops.first;
  if (firstStop == current) return NavigationResult.none;

  return NavigationResult(position: firstStop, preferredX: 0.0);
}