@@ -3372,7 +3372,7 @@ void main() {
3372
3372
);
3373
3373
3374
3374
testWidgets (
3375
- 'long press drag moves the cursor under the drag and shows toolbar on lift (iOS) ' ,
3375
+ 'long press drag extends the selection to the word under the drag and shows toolbar on lift on non-Apple platforms ' ,
3376
3376
(WidgetTester tester) async {
3377
3377
await tester.pumpWidget (
3378
3378
const MaterialApp (
@@ -3384,10 +3384,84 @@ void main() {
3384
3384
),
3385
3385
);
3386
3386
3387
- final Offset selectableTextStart = tester.getTopLeft (find.byType (SelectableText ));
3387
+ final TestGesture gesture =
3388
+ await tester.startGesture (textOffsetToPosition (tester, 18 ));
3389
+ await tester.pump (const Duration (milliseconds: 500 ));
3390
+
3391
+ final EditableText editableTextWidget = tester.widget (find.byType (EditableText ).first);
3392
+ final TextEditingController controller = editableTextWidget.controller;
3393
+
3394
+ // Long press selects the word at the long presses position.
3395
+ expect (
3396
+ controller.selection,
3397
+ const TextSelection (baseOffset: 13 , extentOffset: 23 ),
3398
+ );
3399
+ // Cursor move doesn't trigger a toolbar initially.
3400
+ expect (find.byType (TextButton ), findsNothing);
3401
+
3402
+ await gesture.moveBy (const Offset (100 , 0 ));
3403
+ await tester.pump ();
3404
+
3405
+ // The selection is now moved with the drag.
3406
+ expect (
3407
+ controller.selection,
3408
+ const TextSelection (baseOffset: 13 , extentOffset: 35 ),
3409
+ );
3410
+ // Still no toolbar.
3411
+ expect (find.byType (TextButton ), findsNothing);
3412
+
3413
+ // The selection is moved on a backwards drag.
3414
+ await gesture.moveBy (const Offset (- 200 , 0 ));
3415
+ await tester.pump ();
3416
+
3417
+ // The selection is now moved with the drag.
3418
+ expect (
3419
+ controller.selection,
3420
+ const TextSelection (baseOffset: 23 , extentOffset: 8 ),
3421
+ );
3422
+ // Still no toolbar.
3423
+ expect (find.byType (TextButton ), findsNothing);
3424
+
3425
+ await gesture.moveBy (const Offset (- 100 , 0 ));
3426
+ await tester.pump ();
3427
+
3428
+ // The selection is now moved with the drag.
3429
+ expect (
3430
+ controller.selection,
3431
+ const TextSelection (baseOffset: 23 , extentOffset: 0 ),
3432
+ );
3433
+ // Still no toolbar.
3434
+ expect (find.byType (TextButton ), findsNothing);
3435
+
3436
+ await gesture.up ();
3437
+ await tester.pumpAndSettle ();
3438
+
3439
+ // The selection isn't affected by the gesture lift.
3440
+ expect (
3441
+ controller.selection,
3442
+ const TextSelection (baseOffset: 23 , extentOffset: 0 ),
3443
+ );
3444
+ // The toolbar now shows up.
3445
+ expect (find.byType (TextButton ), findsNWidgets (2 ));
3446
+ },
3447
+ variant: TargetPlatformVariant .all (excluding: < TargetPlatform > { TargetPlatform .iOS, TargetPlatform .macOS }),
3448
+ );
3449
+
3450
+ testWidgets (
3451
+ 'long press drag extends the selection to the word under the drag and shows toolbar on lift (iOS)' ,
3452
+ (WidgetTester tester) async {
3453
+ await tester.pumpWidget (
3454
+ const MaterialApp (
3455
+ home: Material (
3456
+ child: Center (
3457
+ child: SelectableText ('Atwater Peel Sherbrooke Bonaventure' ),
3458
+ ),
3459
+ ),
3460
+ ),
3461
+ );
3388
3462
3389
3463
final TestGesture gesture =
3390
- await tester.startGesture (selectableTextStart + const Offset ( 50.0 , 5.0 ));
3464
+ await tester.startGesture (textOffsetToPosition (tester, 18 ));
3391
3465
await tester.pump (const Duration (milliseconds: 500 ));
3392
3466
3393
3467
final EditableText editableTextWidget = tester.widget (find.byType (EditableText ).first);
@@ -3397,36 +3471,52 @@ void main() {
3397
3471
expect (
3398
3472
controller.selection,
3399
3473
const TextSelection (
3400
- baseOffset: 0 ,
3401
- extentOffset: 7 ,
3474
+ baseOffset: 13 ,
3475
+ extentOffset: 23 ,
3402
3476
),
3403
3477
);
3404
- // Cursor move doesn't trigger a toolbar initially.
3478
+ // Word select doesn't trigger a toolbar initially.
3405
3479
expect (find.byType (CupertinoButton ), findsNothing);
3406
3480
3407
3481
await gesture.moveBy (const Offset (100 , 0 ));
3408
3482
await tester.pump ();
3409
3483
3410
- // The selection position is now moved with the drag.
3484
+ // The selection is now moved with the drag.
3411
3485
expect (
3412
3486
controller.selection,
3413
3487
const TextSelection (
3414
- baseOffset: 0 ,
3415
- extentOffset: 12 ,
3488
+ baseOffset: 13 ,
3489
+ extentOffset: 35 ,
3416
3490
),
3417
3491
);
3418
3492
// Still no toolbar.
3419
3493
expect (find.byType (CupertinoButton ), findsNothing);
3420
3494
3421
- await gesture.moveBy (const Offset (100 , 0 ));
3495
+ // The selection is moved with a backwards drag.
3496
+ await gesture.moveBy (const Offset (- 200 , 0 ));
3422
3497
await tester.pump ();
3423
3498
3424
- // The selection position is now moved with the drag.
3499
+ // The selection is now moved with the drag.
3425
3500
expect (
3426
3501
controller.selection,
3427
3502
const TextSelection (
3428
- baseOffset: 0 ,
3429
- extentOffset: 23 ,
3503
+ baseOffset: 23 ,
3504
+ extentOffset: 8 ,
3505
+ ),
3506
+ );
3507
+ // Still no toolbar.
3508
+ expect (find.byType (CupertinoButton ), findsNothing);
3509
+
3510
+ // The selection is moved with a backwards drag.
3511
+ await gesture.moveBy (const Offset (- 100 , 0 ));
3512
+ await tester.pump ();
3513
+
3514
+ // The selection is now moved with the drag.
3515
+ expect (
3516
+ controller.selection,
3517
+ const TextSelection (
3518
+ baseOffset: 23 ,
3519
+ extentOffset: 0 ,
3430
3520
),
3431
3521
);
3432
3522
// Still no toolbar.
@@ -3439,8 +3529,8 @@ void main() {
3439
3529
expect (
3440
3530
controller.selection,
3441
3531
const TextSelection (
3442
- baseOffset: 0 ,
3443
- extentOffset: 23 ,
3532
+ baseOffset: 23 ,
3533
+ extentOffset: 0 ,
3444
3534
),
3445
3535
);
3446
3536
// The toolbar now shows up.
0 commit comments