eraseRange method
Erase cells whose index satisfies start <= index < end. Erased cells
are filled with style.
Implementation
void eraseRange(
int start,
int end,
CursorStyle style, {
bool respectProtected = false,
}) {
// reset cell one to the left if start is second cell of a wide char.
// Guarded by start < end (a non-empty range): if nothing is erased at
// start, its lead must be left alone too, or an intact wide pair gets
// torn apart by an empty-range call.
if (start > 0 &&
start < end &&
getWidth(start - 1) == 2 &&
_canErase(start - 1, respectProtected)) {
eraseCell(start - 1, style);
}
// If end lands on the placeholder half of a wide char whose lead (at
// end - 1) is inside the erased range, erase the placeholder too -
// otherwise the lead below gets cleared and this placeholder is left
// behind as an orphaned width-0 cell with no lead. end - 1 >= start
// guards an empty range (start == end): the lead isn't erased below in
// that case, so the placeholder must be left alone too.
if (end > 0 &&
end < _length &&
end - 1 >= start &&
getWidth(end - 1) == 2 &&
_canErase(end, respectProtected)) {
eraseCell(end, style);
}
end = min(end, _length);
for (var i = start; i < end; i++) {
if (!_canErase(i, respectProtected)) continue;
eraseCell(i, style);
}
}