selectWord method

void selectWord(
  1. Buffer buffer,
  2. int col,
  3. int row, {
  4. SelectionRegion? region,
})

Selects the contiguous word at (col, row) in buffer.

Implementation

void selectWord(Buffer buffer, int col, int row, {SelectionRegion? region}) {
  if (buffer.width <= 0 || row < 0 || row >= buffer.height) return;
  final minCol = region != null ? max(0, region.minCol) : 0;
  final maxCol = region != null
      ? min(buffer.width - 1, region.maxCol)
      : buffer.width - 1;
  final minRow = region != null ? max(0, region.minRow) : 0;
  final maxRow = region != null
      ? min(buffer.height - 1, region.maxRow)
      : buffer.height - 1;
  if (minCol > maxCol || minRow > maxRow) return;

  final clampedRow = row.clamp(minRow, maxRow);
  final clampedCol = col.clamp(minCol, maxCol);
  final (startCol, endCol) = _expandWordBounds(
    buffer,
    clampedRow,
    clampedCol,
    minCol,
    maxCol,
  );

  _mode = SelectionMode.word;
  _region = region;
  _anchor = SelectionPoint(startCol, clampedRow);
  _focus = SelectionPoint(endCol, clampedRow);
  _wordAnchor = (_anchor!, _focus!);
  notifyListeners();
}