findLineForStop function

({int lineIndex, int stopIndexInLine})? findLineForStop(
  1. List<LogicalLine> lines,
  2. CaretStop stop
)

Implementation

({int lineIndex, int stopIndexInLine})? findLineForStop(
  List<LogicalLine> lines,
  CaretStop stop,
) {
  if (!identical(lines, _linesRefForLineIndex)) {
    _linesRefForLineIndex = lines;
    final m = <CaretStop, ({int lineIndex, int stopIndexInLine})>{};
    for (int i = 0; i < lines.length; i++) {
      for (int j = 0; j < lines[i].stops.length; j++) {
        m[lines[i].stops[j]] = (lineIndex: i, stopIndexInLine: j);
      }
    }
    _stopToLineIndex = m;
  }

  return _stopToLineIndex?[stop];
}