Skip to content

Commit

Permalink
Update SelectableRegion test for M3 (#129627)
Browse files Browse the repository at this point in the history
## 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.
  • Loading branch information
bleroux authored Aug 30, 2023
1 parent 56ea352 commit 1fe2495
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 3 additions & 3 deletions packages/flutter/lib/src/widgets/selectable_region.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 6 additions & 2 deletions packages/flutter/test/widgets/selectable_region_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1570,7 +1570,6 @@ void main() {
final UniqueKey outerText = UniqueKey();
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(useMaterial3: false),
home: SelectableRegion(
focusNode: FocusNode(),
selectionControls: materialTextSelectionControls,
Expand All @@ -1595,8 +1594,13 @@ void main() {
),
);
final RenderParagraph paragraph = tester.renderObject<RenderParagraph>(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();
Expand Down

0 comments on commit 1fe2495

Please sign in to comment.