insert method

void insert(
  1. int position,
  2. String text
)

Implementation

void insert(int position, String text) {
  if (text.isEmpty) return;
  final index = position.clamp(0, length);
  final runes = text.runes.toList();
  var offset = index;
  for (var start = 0; start < runes.length; start += _leafCapacity) {
    final chunk = String.fromCharCodes(runes.skip(start).take(_leafCapacity));
    final split = _root.insert(offset, chunk);
    if (split != null) {
      _root = _RopeNode.internal([_root, split]);
    }
    offset += chunk.runes.length;
  }
}