remove method

void remove(
  1. int start, [
  2. int? end
])

Removes the selection range from start to end.

Implementation

void remove(int start, [int? end]) {
  if (_tree.isEmpty) return;
  start = max(start, first);
  end = min(end ?? start, last);
  final removal = _tree.intersection(IntervalTree([start, end]));
  for (final range in removal) {
    for (int i = range.start; i <= range.end; ++i) {
      notifyListeners(i, false);
    }
  }
  final startAtBounds = _tree.contains([start - 1, start - 1]) &&
      !_tree.contains([start - 2, start - 2]);
  final endAtBounds = _tree.contains([end + 1, end + 1]) &&
      !_tree.contains([end + 2, end + 2]);
  _tree.remove([start - 1, end + 1]);
  if (startAtBounds) _tree.add([start - 1, start - 1]);
  if (endAtBounds) _tree.add([end + 1, end + 1]);
}