moveRight function

NavigationResult moveRight(
  1. Root root,
  2. CaretStop current, {
  3. List<CaretStop>? stops,
  4. List<LogicalLine>? cachedLines,
})

Implementation

NavigationResult moveRight(Root root, CaretStop current, {
  List<CaretStop>? stops,
  List<LogicalLine>? cachedLines,
}) {
  final stops_ = stops ?? buildAllStops(root);
  int idx = findStopIndex(stops_, current.fragmentId, current.offset);

  if (idx < 0) {
    final lines = cachedLines ?? buildAllLogicalLines(root);
    idx = _findStopIndexInLines(lines, current.fragmentId, current.offset);
    if (idx < 0) return NavigationResult.none;
    final stopsFromLines = lines.expand((l) => l.stops).toList();
    if (idx >= stopsFromLines.length - 1) return NavigationResult.none;
    final newStop = stopsFromLines[idx + 1];
    return NavigationResult(position: newStop, preferredX: 0.0);
  }

  if (idx >= stops_.length - 1) return NavigationResult.none;
  final newStop = stops_[idx + 1];
  return NavigationResult(position: newStop, preferredX: 0.0);
}