handleSelectWord method
- SelectWordSelectionEvent event
Selects a word in a selectable at the location SelectWordSelectionEvent.globalPosition.
Implementation
@protected
SelectionResult handleSelectWord(SelectWordSelectionEvent event) {
SelectionResult? lastSelectionResult;
for (int index = 0; index < selectables.length; index += 1) {
bool globalRectsContainsPosition = false;
if (selectables[index].boundingBoxes.isNotEmpty) {
for (final Rect rect in selectables[index].boundingBoxes) {
final Rect globalRect = MatrixUtils.transformRect(selectables[index].getTransformTo(null), rect);
if (globalRect.contains(event.globalPosition)) {
globalRectsContainsPosition = true;
break;
}
}
}
if (globalRectsContainsPosition) {
final SelectionGeometry existingGeometry = selectables[index].value;
lastSelectionResult = dispatchSelectionEventToChild(selectables[index], event);
if (index == selectables.length - 1 && lastSelectionResult == SelectionResult.next) {
return SelectionResult.next;
}
if (lastSelectionResult == SelectionResult.next) {
continue;
}
if (index == 0 && lastSelectionResult == SelectionResult.previous) {
return SelectionResult.previous;
}
if (selectables[index].value != existingGeometry) {
// Geometry has changed as a result of select word, need to clear the
// selection of other selectables to keep selection in sync.
selectables
.where((Selectable target) => target != selectables[index])
.forEach((Selectable target) => dispatchSelectionEventToChild(target, const ClearSelectionEvent()));
currentSelectionStartIndex = currentSelectionEndIndex = index;
}
return SelectionResult.end;
} else {
if (lastSelectionResult == SelectionResult.next) {
currentSelectionStartIndex = currentSelectionEndIndex = index - 1;
return SelectionResult.end;
}
}
}
assert(lastSelectionResult == null);
return SelectionResult.end;
}