resize method
Resizes the buffer to width × height, preserving content where possible.
Implementation
void resize(int width, int height) {
if (width < 0 || height <= 0) {
lines.clear();
touched = <LineData?>[];
dirtyRows = <bool>[];
dirtyBits = <Uint32List>[];
return;
}
final oldHeight = lines.length;
final oldWidth = oldHeight == 0 ? 0 : lines[0].length;
// Resize height.
if (height > oldHeight) {
for (var i = oldHeight; i < height; i++) {
lines.add(Line.filled(width));
}
} else if (height < oldHeight) {
lines.removeRange(height, oldHeight);
}
// Resize width (rebuild lines to keep wide-placeholder invariants simple).
if (width != oldWidth && lines.isNotEmpty) {
for (var y = 0; y < lines.length; y++) {
final newLine = Line.filled(width);
final copyWidth = width < oldWidth ? width : oldWidth;
for (var x = 0; x < copyWidth; x++) {
newLine.replaceWithClone(x, lines[y].cells[x]);
}
lines[y] = newLine;
}
}
touched = List<LineData?>.filled(lines.length, null);
dirtyRows = List<bool>.filled(lines.length, false);
dirtyBits = List<Uint32List>.generate(
lines.length,
(_) => Uint32List(_dirtyWordCount(width)),
);
}