skipAtomicRanges function

int skipAtomicRanges(
  1. List<RangeSet<RangeValue>> atoms,
  2. int pos,
  3. int bias
)

Skip atomic ranges starting from pos in the given direction.

Returns the position after skipping any atomic ranges.

Implementation

int skipAtomicRanges(List<RangeSet<RangeValue>> atoms, int pos, int bias) {
  while (true) {
    var moved = 0;

    for (final set in atoms) {
      set.between(pos - 1, pos + 1, (from, to, value) {
        if (pos > from && pos < to) {
          final side = moved != 0 ? moved : (bias != 0 ? bias : (pos - from < to - pos ? -1 : 1));
          pos = side < 0 ? from : to;
          moved = side;
        }
        return true;
      });
    }

    if (moved == 0) return pos;
  }
}