isLineInFoldedRegion method

bool isLineInFoldedRegion(
  1. int lineIndex
)

Check whether the corresponding lineIndex is inside a folded code block or not.

Implementation

bool isLineInFoldedRegion(int lineIndex) {
  final starts = _foldedStartsSorted;
  final ends = _foldedEndsSorted;
  if (starts.isEmpty) return false;

  int lo = 0, hi = starts.length - 1;
  while (lo <= hi) {
    final mid = (lo + hi) >> 1;
    if (starts[mid] < lineIndex) {
      lo = mid + 1;
    } else {
      hi = mid - 1;
    }
  }

  for (int i = hi; i >= 0; i--) {
    if (starts[i] >= lineIndex) continue;
    if (ends[i] >= lineIndex) return true;
    if (lineIndex - starts[i] > 100000) break;
  }
  return false;
}