diff --git a/packages/flutter/lib/src/widgets/selectable_region.dart b/packages/flutter/lib/src/widgets/selectable_region.dart index f08e20ec2551..17abff5de57b 100644 --- a/packages/flutter/lib/src/widgets/selectable_region.dart +++ b/packages/flutter/lib/src/widgets/selectable_region.dart @@ -2052,15 +2052,15 @@ abstract class MultiSelectableSelectionContainerDelegate extends SelectionContai if (globalRect.contains(event.globalPosition)) { 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 (index == selectables.length - 1 && lastSelectionResult == SelectionResult.next) { - return SelectionResult.next; - } 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. diff --git a/packages/flutter/test/widgets/selectable_region_test.dart b/packages/flutter/test/widgets/selectable_region_test.dart index a2e8bcb67fad..b4e3f5d0eeb4 100644 --- a/packages/flutter/test/widgets/selectable_region_test.dart +++ b/packages/flutter/test/widgets/selectable_region_test.dart @@ -1570,7 +1570,6 @@ void main() { final UniqueKey outerText = UniqueKey(); await tester.pumpWidget( MaterialApp( - theme: ThemeData(useMaterial3: false), home: SelectableRegion( focusNode: FocusNode(), selectionControls: materialTextSelectionControls, @@ -1595,8 +1594,13 @@ void main() { ), ); final RenderParagraph paragraph = tester.renderObject(find.descendant(of: find.byKey(outerText), matching: find.byType(RichText)).first); + + // Adjust `textOffsetToPosition` result because it returns the wrong vertical position (wrong line). + // TODO(bleroux): Remove when https://github.com/flutter/flutter/issues/133637 is fixed. + final Offset gestureOffset = textOffsetToPosition(paragraph, 125).translate(0, 10); + // Right click to select word at position. - final TestGesture gesture = await tester.startGesture(textOffsetToPosition(paragraph, 125), kind: PointerDeviceKind.mouse, buttons: kSecondaryMouseButton); + final TestGesture gesture = await tester.startGesture(gestureOffset, kind: PointerDeviceKind.mouse, buttons: kSecondaryMouseButton); addTearDown(gesture.removePointer); await tester.pump(); await gesture.up();