delete method

  1. @override
void delete(
  1. int index,
  2. int length
)
override

Delete length characters of this node starting from index.

Implementation

@override
void delete(int index, int length) {
  assert(index < this.length);

  final local = math.min(this.length - index, length);
  final target = isolate(index, local);
  // Memorize siblings before un-linking.
  final needsOptimize = target.previous;
  final actualNext = target.next;
  target.unlink();

  final remaining = length - local;
  if (remaining > 0) {
    assert(actualNext != null);
    actualNext.delete(0, remaining);
  }

  if (needsOptimize != null) needsOptimize.optimize();
}