@@ -1017,7 +1017,6 @@ void main() {
1017
1017
);
1018
1018
// On iOS/iPadOS, during a tap we select the edge of the word closest to the tap.
1019
1019
// On macOS, we select the precise position of the tap.
1020
- final bool isTargetPlatformMobile = defaultTargetPlatform == TargetPlatform .iOS;
1021
1020
await tester.pumpWidget (
1022
1021
MaterialApp (
1023
1022
home: Material (
@@ -1031,21 +1030,19 @@ void main() {
1031
1030
),
1032
1031
);
1033
1032
1034
- final Offset textfieldStart = tester.getTopLeft (find.byType (TextField ));
1035
-
1036
1033
// This tap just puts the cursor somewhere different than where the double
1037
1034
// 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 ));
1039
1036
await tester.pump (const Duration (milliseconds: 500 ));
1040
1037
1041
- await tester.tapAt (textfieldStart + const Offset ( 150.0 , 9.0 ));
1038
+ await tester.tapAt (textOffsetToPosition (tester, 8 ));
1042
1039
await tester.pump (const Duration (milliseconds: 50 ));
1043
1040
// First tap moved the cursor.
1044
1041
expect (
1045
1042
controller.selection,
1046
- TextSelection .collapsed (offset: isTargetPlatformMobile ? 8 : 9 ),
1043
+ const TextSelection .collapsed (offset: 8 ),
1047
1044
);
1048
- await tester.tapAt (textfieldStart + const Offset ( 150.0 , 9.0 ));
1045
+ await tester.tapAt (textOffsetToPosition (tester, 8 ));
1049
1046
await tester.pump ();
1050
1047
1051
1048
// Second tap selects the word around the cursor.
@@ -2088,14 +2085,14 @@ void main() {
2088
2085
await touchGesture.up ();
2089
2086
await tester.pumpAndSettle (kDoubleTapTimeout);
2090
2087
// 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 );
2093
2090
2094
2091
// Selection should stay the same since it is set on tap up for mobile platforms.
2095
2092
await touchGesture.down (gPos);
2096
2093
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 );
2099
2096
2100
2097
await touchGesture.up ();
2101
2098
await tester.pumpAndSettle ();
@@ -8414,14 +8411,11 @@ void main() {
8414
8411
);
8415
8412
8416
8413
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) ' ,
8418
8415
(WidgetTester tester) async {
8419
8416
final TextEditingController controller = TextEditingController (
8420
8417
text: 'Atwater Peel Sherbrooke Bonaventure' ,
8421
8418
);
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;
8425
8419
await tester.pumpWidget (
8426
8420
MaterialApp (
8427
8421
home: Material (
@@ -8447,7 +8441,7 @@ void main() {
8447
8441
// First tap moved the cursor.
8448
8442
expect (
8449
8443
controller.selection,
8450
- TextSelection .collapsed (offset: isTargetPlatformMobile ? 8 : 9 ),
8444
+ const TextSelection .collapsed (offset: 12 , affinity : TextAffinity .upstream ),
8451
8445
);
8452
8446
await tester.tapAt (pPos);
8453
8447
await tester.pumpAndSettle ();
@@ -8464,6 +8458,37 @@ void main() {
8464
8458
variant: const TargetPlatformVariant (< TargetPlatform > { TargetPlatform .iOS }),
8465
8459
);
8466
8460
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
+
8467
8492
testWidgets (
8468
8493
'double tap does not select word on read-only obscured field' ,
8469
8494
(WidgetTester tester) async {
@@ -8952,7 +8977,7 @@ void main() {
8952
8977
// First tap moved the cursor.
8953
8978
expect (
8954
8979
controller.selection,
8955
- TextSelection .collapsed (offset: isTargetPlatformMobile ? 8 : 9 ),
8980
+ isTargetPlatformMobile ? const TextSelection .collapsed (offset: 12 , affinity : TextAffinity .upstream) : const TextSelection . collapsed (offset : 9 ),
8956
8981
);
8957
8982
await tester.tapAt (pPos);
8958
8983
await tester.pump (const Duration (milliseconds: 500 ));
@@ -9813,7 +9838,7 @@ void main() {
9813
9838
// First tap moved the cursor to the beginning of the second word.
9814
9839
expect (
9815
9840
controller.selection,
9816
- TextSelection .collapsed (offset: isTargetPlatformMobile ? 8 : 9 ),
9841
+ isTargetPlatformMobile ? const TextSelection .collapsed (offset: 12 , affinity : TextAffinity .upstream) : const TextSelection . collapsed (offset : 9 ),
9817
9842
);
9818
9843
await tester.tapAt (pPos);
9819
9844
await tester.pump (const Duration (milliseconds: 500 ));
@@ -9875,7 +9900,7 @@ void main() {
9875
9900
// First tap moved the cursor.
9876
9901
expect (
9877
9902
controller.selection,
9878
- TextSelection .collapsed (offset: isTargetPlatformMobile ? 8 : 9 ),
9903
+ isTargetPlatformMobile ? const TextSelection .collapsed (offset: 12 , affinity : TextAffinity .upstream) : const TextSelection . collapsed (offset : 9 ),
9879
9904
);
9880
9905
await tester.tapAt (pPos);
9881
9906
await tester.pumpAndSettle ();
@@ -10006,7 +10031,7 @@ void main() {
10006
10031
// First tap moved the cursor and hid the toolbar.
10007
10032
expect (
10008
10033
controller.selection,
10009
- const TextSelection .collapsed (offset: 8 ),
10034
+ const TextSelection .collapsed (offset: 12 , affinity : TextAffinity .upstream)
10010
10035
);
10011
10036
expect (find.byType (CupertinoButton ), findsNothing);
10012
10037
await tester.tapAt (textfieldStart + const Offset (150.0 , 9.0 ));
@@ -10441,7 +10466,7 @@ void main() {
10441
10466
// Single taps selects the edge of the word.
10442
10467
expect (
10443
10468
controller.selection,
10444
- const TextSelection .collapsed (offset: 8 ),
10469
+ const TextSelection .collapsed (offset: 12 , affinity : TextAffinity .upstream ),
10445
10470
);
10446
10471
10447
10472
await tester.pump ();
@@ -13418,7 +13443,7 @@ void main() {
13418
13443
await tester.tapAt (textOffsetToPosition (tester, testValue.indexOf ('e' )));
13419
13444
await tester.pumpAndSettle (const Duration (milliseconds: 300 ));
13420
13445
expect (controller.selection.isCollapsed, true );
13421
- expect (controller.selection.baseOffset, isTargetPlatformAndroid ? 5 : 4 );
13446
+ expect (controller.selection.baseOffset, isTargetPlatformAndroid ? 5 : 7 );
13422
13447
expect (find.byKey (fakeMagnifier.key! ), findsNothing);
13423
13448
13424
13449
// Long press the 'e' to select 'def' on Android and show magnifier.
0 commit comments