updateWordSelection method
Extends a word-snapped selection from the initial _wordAnchor to the
word at (col, row) in buffer, supporting forward, backward, and
direction-reversed drags across wide graphemes.
Implementation
void updateWordSelection(Buffer buffer, int col, int row) {
if (_anchor == null || buffer.width <= 0 || buffer.height <= 0) return;
final r = _region;
final minCol = r != null ? max(0, r.minCol) : 0;
final maxCol = r != null
? min(buffer.width - 1, r.maxCol)
: buffer.width - 1;
final minRow = r != null ? max(0, r.minRow) : 0;
final maxRow = r != null
? min(buffer.height - 1, r.maxRow)
: buffer.height - 1;
if (minCol > maxCol || minRow > maxRow) return;
final clampedCol = col.clamp(minCol, maxCol);
final clampedRow = row.clamp(minRow, maxRow);
final (targetStart, targetEnd) = _expandWordBounds(
buffer,
clampedRow,
clampedCol,
minCol,
maxCol,
);
final (anchorStart, anchorEnd) =
_wordAnchor ?? _orderPoints(_anchor!, _focus ?? _anchor!);
final (
SelectionPoint nextAnchor,
SelectionPoint nextFocus,
) = _resolveWordDragEndpoints(
anchorStart: anchorStart,
anchorEnd: anchorEnd,
clampedRow: clampedRow,
targetStart: targetStart,
targetEnd: targetEnd,
);
if (_mode == SelectionMode.word &&
_anchor == nextAnchor &&
_focus == nextFocus) {
return;
}
_mode = SelectionMode.word;
_anchor = nextAnchor;
_focus = nextFocus;
notifyListeners();
}