File tree 2 files changed +41
-8
lines changed
2 files changed +41
-8
lines changed Original file line number Diff line number Diff line change @@ -558,21 +558,15 @@ class _SelectableTextState extends State<SelectableText> implements TextSelectio
558
558
});
559
559
}
560
560
561
- TextSelection ? _lastSeenTextSelection;
562
-
563
561
void _handleSelectionChanged (TextSelection selection, SelectionChangedCause ? cause) {
564
562
final bool willShowSelectionHandles = _shouldShowSelectionHandles (cause);
565
563
if (willShowSelectionHandles != _showSelectionHandles) {
566
564
setState (() {
567
565
_showSelectionHandles = willShowSelectionHandles;
568
566
});
569
567
}
570
- // TODO(chunhtai): The selection may be the same. We should remove this
571
- // check once this is fixed https://github.com/flutter/flutter/issues/76349.
572
- if (widget.onSelectionChanged != null && _lastSeenTextSelection != selection) {
573
- widget.onSelectionChanged !(selection, cause);
574
- }
575
- _lastSeenTextSelection = selection;
568
+
569
+ widget.onSelectionChanged? .call (selection, cause);
576
570
577
571
switch (Theme .of (context).platform) {
578
572
case TargetPlatform .iOS:
Original file line number Diff line number Diff line change @@ -5367,4 +5367,43 @@ void main() {
5367
5367
final EditableText editableText = tester.widget (find.byType (EditableText ));
5368
5368
expect (editableText.style.fontSize, textStyle.fontSize);
5369
5369
});
5370
+
5371
+ testWidgets ('SelectableText text span style is merged with default text style' , (WidgetTester tester) async {
5372
+ TextSelection ? selection;
5373
+ int count = 0 ;
5374
+
5375
+ await tester.pumpWidget (
5376
+ MaterialApp (
5377
+ home: SelectableText (
5378
+ 'I love Flutter!' ,
5379
+ onSelectionChanged: (TextSelection s, _) {
5380
+ selection = s;
5381
+ count++ ;
5382
+ },
5383
+ ),
5384
+ ),
5385
+ );
5386
+
5387
+ expect (selection, null );
5388
+ expect (count, 0 );
5389
+
5390
+ // Tap to put the cursor before the "F".
5391
+ const int index = 7 ;
5392
+ await tester.tapAt (textOffsetToPosition (tester, index));
5393
+ await tester.pump (const Duration (milliseconds: 500 ));
5394
+ expect (
5395
+ selection,
5396
+ const TextSelection .collapsed (offset: index),
5397
+ );
5398
+ expect (count, 1 ); // The `onSelectionChanged` will be triggered one time.
5399
+
5400
+ // Tap on the same location again.
5401
+ await tester.tapAt (textOffsetToPosition (tester, index));
5402
+ await tester.pump (const Duration (milliseconds: 50 ));
5403
+ expect (
5404
+ selection,
5405
+ const TextSelection .collapsed (offset: index),
5406
+ );
5407
+ expect (count, 1 ); // The `onSelectionChanged` will not be triggered.
5408
+ });
5370
5409
}
You can’t perform that action at this time.
0 commit comments