Skip to content

Commit 1fe2495

Browse files
authored
Update SelectableRegion test for M3 (#129627)
## Description This PR fixes one selectable region test failure when switching to M3. The failure is somewhat tricky because it is related to the M3 typography (line height set to 1.43). ## Related Issue fixes flutter/flutter#129626 ## Tests Updates 1 test.
1 parent 56ea352 commit 1fe2495

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

packages/flutter/lib/src/widgets/selectable_region.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2052,15 +2052,15 @@ abstract class MultiSelectableSelectionContainerDelegate extends SelectionContai
20522052
if (globalRect.contains(event.globalPosition)) {
20532053
final SelectionGeometry existingGeometry = selectables[index].value;
20542054
lastSelectionResult = dispatchSelectionEventToChild(selectables[index], event);
2055+
if (index == selectables.length - 1 && lastSelectionResult == SelectionResult.next) {
2056+
return SelectionResult.next;
2057+
}
20552058
if (lastSelectionResult == SelectionResult.next) {
20562059
continue;
20572060
}
20582061
if (index == 0 && lastSelectionResult == SelectionResult.previous) {
20592062
return SelectionResult.previous;
20602063
}
2061-
if (index == selectables.length - 1 && lastSelectionResult == SelectionResult.next) {
2062-
return SelectionResult.next;
2063-
}
20642064
if (selectables[index].value != existingGeometry) {
20652065
// Geometry has changed as a result of select word, need to clear the
20662066
// selection of other selectables to keep selection in sync.

packages/flutter/test/widgets/selectable_region_test.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,7 +1570,6 @@ void main() {
15701570
final UniqueKey outerText = UniqueKey();
15711571
await tester.pumpWidget(
15721572
MaterialApp(
1573-
theme: ThemeData(useMaterial3: false),
15741573
home: SelectableRegion(
15751574
focusNode: FocusNode(),
15761575
selectionControls: materialTextSelectionControls,
@@ -1595,8 +1594,13 @@ void main() {
15951594
),
15961595
);
15971596
final RenderParagraph paragraph = tester.renderObject<RenderParagraph>(find.descendant(of: find.byKey(outerText), matching: find.byType(RichText)).first);
1597+
1598+
// Adjust `textOffsetToPosition` result because it returns the wrong vertical position (wrong line).
1599+
// TODO(bleroux): Remove when https://github.com/flutter/flutter/issues/133637 is fixed.
1600+
final Offset gestureOffset = textOffsetToPosition(paragraph, 125).translate(0, 10);
1601+
15981602
// Right click to select word at position.
1599-
final TestGesture gesture = await tester.startGesture(textOffsetToPosition(paragraph, 125), kind: PointerDeviceKind.mouse, buttons: kSecondaryMouseButton);
1603+
final TestGesture gesture = await tester.startGesture(gestureOffset, kind: PointerDeviceKind.mouse, buttons: kSecondaryMouseButton);
16001604
addTearDown(gesture.removePointer);
16011605
await tester.pump();
16021606
await gesture.up();

0 commit comments

Comments
 (0)