copyFrom method
Copies len cells from src starting at srcCol to dstCol at this
line.
Implementation
void copyFrom(BufferLine src, int srcCol, int dstCol, int len) {
final requiredLength = dstCol + len;
if (requiredLength > _length) {
resize(requiredLength);
}
final dstEnd = dstCol + len;
final srcEnd = srcCol + len;
final leftBoundarySplitsWideCell = dstCol > 0 && srcCol > 0;
final rightBoundarySplitsWideCell = dstEnd < _length && srcEnd > 0;
Map<int, String>? copiedCombiningCharacters;
Map<int, int>? copiedUnderlineColors;
if (src._combiningCharacters case final combiningCharacters?) {
for (final entry in combiningCharacters.entries) {
if (entry.key < srcCol || entry.key >= srcCol + len) continue;
final destination = dstCol + entry.key - srcCol;
(copiedCombiningCharacters ??= <int, String>{})[destination] =
entry.value;
}
}
if (src._underlineColors case final underlineColors?) {
for (final entry in underlineColors.entries) {
if (entry.key < srcCol || entry.key >= srcCol + len) continue;
final destination = dstCol + entry.key - srcCol;
(copiedUnderlineColors ??= <int, int>{})[destination] = entry.value;
}
}
// data.setRange(
// dstCol * _cellSize,
// (dstCol + len) * _cellSize,
// Uint32List.sublistView(src.data, srcCol * _cellSize, len * _cellSize),
// );
final srcOffset = srcCol * _cellSize;
final dstOffset = dstCol * _cellSize;
_data.setRange(
dstOffset,
dstOffset + len * _cellSize,
src._data,
srcOffset,
);
if (_combiningCharacters case final combiningCharacters?) {
combiningCharacters.removeWhere(
(index, _) => index >= dstCol && index < dstCol + len,
);
if (combiningCharacters.isEmpty) _combiningCharacters = null;
}
if (copiedCombiningCharacters case final copied?) {
_mutableCombiningCharacters.addAll(copied);
}
if (_underlineColors case final underlineColors?) {
underlineColors.removeWhere(
(index, _) => index >= dstCol && index < dstCol + len,
);
if (underlineColors.isEmpty) _underlineColors = null;
}
if (copiedUnderlineColors case final copied?) {
_mutableUnderlineColors.addAll(copied);
}
if (leftBoundarySplitsWideCell && getWidth(dstCol) == 0) {
resetCell(dstCol);
}
if (rightBoundarySplitsWideCell && getWidth(dstEnd - 1) == 2) {
resetCell(dstEnd - 1);
}
}