selectWordsBetweenPoints method
Attempts to select the words between startPt
and endPt
, returning
true
if successful.
Implementation
bool selectWordsBetweenPoints(Offset startPt, Offset endPt, {int? key}) {
final k = key ?? 0;
if (k < 0) return false;
// First, clear and unhide the selection, or create it if it doesn't exist.
var selection = _selections[k]?.cleared().copyWith(isHidden: false) ??
Selection(rectifier: _rectifiers[k] ?? SelectionRectifiers.identity);
// Next, attempt to select the word under the first point.
selection = selection.updatedWith(
_selections.cachedParagraphs,
SelectionDragInfo(selectionPt: startPt),
);
// Finally, if that worked, and endPt != startPt, attempt to extend the
// selection to include the end point.
if (selection.isTextSelected && endPt != startPt) {
selection = selection.updatedWith(
_selections.cachedParagraphs,
SelectionDragInfo(
selectionPt: endPt,
handleType: SelectionHandleType.right,
),
);
}
if (selection.isTextSelected) {
_selections[k] = selection;
notifyListeners();
return true;
} else if (startPt == endPt) {
// dmPrint('WARNING: Selectable selectWordAtPoint($startPt) failed.');
} else {
// dmPrint('WARNING: Selectable '
// 'selectWordsBetweenPoints($startPt, $endPt) failed.');
}
return false;
}