selectCell method
Select the cell at (row, col). additive toggles it (multi), range
extends a rectangle from the anchor. Also moves the editing cursor.
Implementation
void selectCell(int row, int col, {bool additive = false, bool range = false}) {
if (!selectionIsCellMode || row < 0 || row >= rowCount || col < 0 || col >= colCount) return;
_sel = CellRef(row, col);
if (selectionMode == EditableSelectionMode.singleCell) {
_selCells
..clear()
..add(CellRef(row, col));
_anchorRow = row;
_anchorCol = col;
} else if (range) {
final r0 = row < _anchorRow ? row : _anchorRow;
final r1 = row < _anchorRow ? _anchorRow : row;
final c0 = col < _anchorCol ? col : _anchorCol;
final c1 = col < _anchorCol ? _anchorCol : col;
if (!additive) _selCells.clear();
for (var r = r0; r <= r1; r++) {
for (var c = c0; c <= c1; c++) {
_selCells.add(CellRef(r, c));
}
}
} else if (additive) {
final cell = CellRef(row, col);
_selCells.contains(cell) ? _selCells.remove(cell) : _selCells.add(cell);
_anchorRow = row;
_anchorCol = col;
} else {
_selCells
..clear()
..add(CellRef(row, col));
_anchorRow = row;
_anchorCol = col;
}
notifyListeners();
}