@@ -1017,7 +1017,6 @@ void main() {
10171017 );
10181018 // On iOS/iPadOS, during a tap we select the edge of the word closest to the tap.
10191019 // On macOS, we select the precise position of the tap.
1020- final bool isTargetPlatformMobile = defaultTargetPlatform == TargetPlatform .iOS;
10211020 await tester.pumpWidget (
10221021 MaterialApp (
10231022 home: Material (
@@ -1031,21 +1030,19 @@ void main() {
10311030 ),
10321031 );
10331032
1034- final Offset textfieldStart = tester.getTopLeft (find.byType (TextField ));
1035-
10361033 // This tap just puts the cursor somewhere different than where the double
10371034 // tap will occur to test that the double tap moves the existing cursor first.
1038- await tester.tapAt (textfieldStart + const Offset ( 50.0 , 9.0 ));
1035+ await tester.tapAt (textOffsetToPosition (tester, 3 ));
10391036 await tester.pump (const Duration (milliseconds: 500 ));
10401037
1041- await tester.tapAt (textfieldStart + const Offset ( 150.0 , 9.0 ));
1038+ await tester.tapAt (textOffsetToPosition (tester, 8 ));
10421039 await tester.pump (const Duration (milliseconds: 50 ));
10431040 // First tap moved the cursor.
10441041 expect (
10451042 controller.selection,
1046- TextSelection .collapsed (offset: isTargetPlatformMobile ? 8 : 9 ),
1043+ const TextSelection .collapsed (offset: 8 ),
10471044 );
1048- await tester.tapAt (textfieldStart + const Offset ( 150.0 , 9.0 ));
1045+ await tester.tapAt (textOffsetToPosition (tester, 8 ));
10491046 await tester.pump ();
10501047
10511048 // Second tap selects the word around the cursor.
@@ -2088,14 +2085,14 @@ void main() {
20882085 await touchGesture.up ();
20892086 await tester.pumpAndSettle (kDoubleTapTimeout);
20902087 // On iOS a tap to select, selects the word edge instead of the exact tap position.
2091- expect (controller.selection.baseOffset, isTargetPlatformApple ? 4 : 5 );
2092- expect (controller.selection.extentOffset, isTargetPlatformApple ? 4 : 5 );
2088+ expect (controller.selection.baseOffset, isTargetPlatformApple ? 7 : 5 );
2089+ expect (controller.selection.extentOffset, isTargetPlatformApple ? 7 : 5 );
20932090
20942091 // Selection should stay the same since it is set on tap up for mobile platforms.
20952092 await touchGesture.down (gPos);
20962093 await tester.pump ();
2097- expect (controller.selection.baseOffset, isTargetPlatformApple ? 4 : 5 );
2098- expect (controller.selection.extentOffset, isTargetPlatformApple ? 4 : 5 );
2094+ expect (controller.selection.baseOffset, isTargetPlatformApple ? 7 : 5 );
2095+ expect (controller.selection.extentOffset, isTargetPlatformApple ? 7 : 5 );
20992096
21002097 await touchGesture.up ();
21012098 await tester.pumpAndSettle ();
@@ -8414,14 +8411,11 @@ void main() {
84148411 );
84158412
84168413 testWidgets (
8417- 'double tap selects word and first tap of double tap moves cursor' ,
8414+ 'double tap selects word and first tap of double tap moves cursor (iOS) ' ,
84188415 (WidgetTester tester) async {
84198416 final TextEditingController controller = TextEditingController (
84208417 text: 'Atwater Peel Sherbrooke Bonaventure' ,
84218418 );
8422- // On iOS/iPadOS, during a tap we select the edge of the word closest to the tap.
8423- // On macOS, we select the precise position of the tap.
8424- final bool isTargetPlatformMobile = defaultTargetPlatform == TargetPlatform .iOS;
84258419 await tester.pumpWidget (
84268420 MaterialApp (
84278421 home: Material (
@@ -8447,7 +8441,7 @@ void main() {
84478441 // First tap moved the cursor.
84488442 expect (
84498443 controller.selection,
8450- TextSelection .collapsed (offset: isTargetPlatformMobile ? 8 : 9 ),
8444+ const TextSelection .collapsed (offset: 12 , affinity : TextAffinity .upstream ),
84518445 );
84528446 await tester.tapAt (pPos);
84538447 await tester.pumpAndSettle ();
@@ -8464,6 +8458,37 @@ void main() {
84648458 variant: const TargetPlatformVariant (< TargetPlatform > { TargetPlatform .iOS }),
84658459 );
84668460
8461+ testWidgets ('iOS selectWordEdge works correctly' , (WidgetTester tester) async {
8462+ final TextEditingController controller = TextEditingController (
8463+ text: 'blah1 blah2' ,
8464+ );
8465+ await tester.pumpWidget (
8466+ MaterialApp (
8467+ home: Material (
8468+ child: TextField (
8469+ controller: controller,
8470+ ),
8471+ ),
8472+ ),
8473+ );
8474+
8475+ // Initially, the menu is not shown and there is no selection.
8476+ expect (controller.selection, const TextSelection (baseOffset: - 1 , extentOffset: - 1 ));
8477+ final Offset pos1 = textOffsetToPosition (tester, 1 );
8478+ TestGesture gesture = await tester.startGesture (pos1);
8479+ await tester.pump ();
8480+ await gesture.up ();
8481+ await tester.pumpAndSettle ();
8482+ expect (controller.selection, const TextSelection .collapsed (offset: 5 , affinity: TextAffinity .upstream));
8483+
8484+ final Offset pos0 = textOffsetToPosition (tester, 0 );
8485+ gesture = await tester.startGesture (pos0);
8486+ await tester.pump ();
8487+ await gesture.up ();
8488+ await tester.pumpAndSettle ();
8489+ expect (controller.selection, const TextSelection .collapsed (offset: 0 ));
8490+ }, variant: TargetPlatformVariant .only (TargetPlatform .iOS));
8491+
84678492 testWidgets (
84688493 'double tap does not select word on read-only obscured field' ,
84698494 (WidgetTester tester) async {
@@ -8952,7 +8977,7 @@ void main() {
89528977 // First tap moved the cursor.
89538978 expect (
89548979 controller.selection,
8955- TextSelection .collapsed (offset: isTargetPlatformMobile ? 8 : 9 ),
8980+ isTargetPlatformMobile ? const TextSelection .collapsed (offset: 12 , affinity : TextAffinity .upstream) : const TextSelection . collapsed (offset : 9 ),
89568981 );
89578982 await tester.tapAt (pPos);
89588983 await tester.pump (const Duration (milliseconds: 500 ));
@@ -9813,7 +9838,7 @@ void main() {
98139838 // First tap moved the cursor to the beginning of the second word.
98149839 expect (
98159840 controller.selection,
9816- TextSelection .collapsed (offset: isTargetPlatformMobile ? 8 : 9 ),
9841+ isTargetPlatformMobile ? const TextSelection .collapsed (offset: 12 , affinity : TextAffinity .upstream) : const TextSelection . collapsed (offset : 9 ),
98179842 );
98189843 await tester.tapAt (pPos);
98199844 await tester.pump (const Duration (milliseconds: 500 ));
@@ -9875,7 +9900,7 @@ void main() {
98759900 // First tap moved the cursor.
98769901 expect (
98779902 controller.selection,
9878- TextSelection .collapsed (offset: isTargetPlatformMobile ? 8 : 9 ),
9903+ isTargetPlatformMobile ? const TextSelection .collapsed (offset: 12 , affinity : TextAffinity .upstream) : const TextSelection . collapsed (offset : 9 ),
98799904 );
98809905 await tester.tapAt (pPos);
98819906 await tester.pumpAndSettle ();
@@ -10006,7 +10031,7 @@ void main() {
1000610031 // First tap moved the cursor and hid the toolbar.
1000710032 expect (
1000810033 controller.selection,
10009- const TextSelection .collapsed (offset: 8 ),
10034+ const TextSelection .collapsed (offset: 12 , affinity : TextAffinity .upstream)
1001010035 );
1001110036 expect (find.byType (CupertinoButton ), findsNothing);
1001210037 await tester.tapAt (textfieldStart + const Offset (150.0 , 9.0 ));
@@ -10441,7 +10466,7 @@ void main() {
1044110466 // Single taps selects the edge of the word.
1044210467 expect (
1044310468 controller.selection,
10444- const TextSelection .collapsed (offset: 8 ),
10469+ const TextSelection .collapsed (offset: 12 , affinity : TextAffinity .upstream ),
1044510470 );
1044610471
1044710472 await tester.pump ();
@@ -13418,7 +13443,7 @@ void main() {
1341813443 await tester.tapAt (textOffsetToPosition (tester, testValue.indexOf ('e' )));
1341913444 await tester.pumpAndSettle (const Duration (milliseconds: 300 ));
1342013445 expect (controller.selection.isCollapsed, true );
13421- expect (controller.selection.baseOffset, isTargetPlatformAndroid ? 5 : 4 );
13446+ expect (controller.selection.baseOffset, isTargetPlatformAndroid ? 5 : 7 );
1342213447 expect (find.byKey (fakeMagnifier.key! ), findsNothing);
1342313448
1342413449 // Long press the 'e' to select 'def' on Android and show magnifier.
0 commit comments