removeCells method
Remove count cells starting at start. Cells that are empty after the
removal are filled with style.
Implementation
void removeCells(int start, int count, [CursorStyle? style]) {
assert(start >= 0 && start < _length);
assert(count >= 0 && start + count <= _length);
style ??= CursorStyle.empty;
if (start + count < _length) {
final moveStart = start * _cellSize;
final moveEnd = (_length - count) * _cellSize;
final moveOffset = count * _cellSize;
_data.setRange(moveStart, moveEnd, _data, moveStart + moveOffset);
}
for (var i = _length - count; i < _length; i++) {
_eraseCellRaw(i, style);
}
if (start > 0 && getWidth(start - 1) == 2) {
_eraseCellRaw(start - 1, style);
}
// Update anchors, remove anchors that are inside the removed range.
// Iterate backwards: disposing an anchor removes it from [_anchors].
for (var i = _anchors.length - 1; i >= 0; i--) {
final anchor = _anchors[i];
if (anchor.x >= start) {
if (anchor.x < start + count) {
anchor.dispose();
} else {
anchor.reposition(anchor.x - count);
}
}
}
version++;
}