This repository was archived by the owner on Feb 22, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +41
-8
lines changed Expand file tree Collapse file tree 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
558558 });
559559 }
560560
561- TextSelection ? _lastSeenTextSelection;
562-
563561 void _handleSelectionChanged (TextSelection selection, SelectionChangedCause ? cause) {
564562 final bool willShowSelectionHandles = _shouldShowSelectionHandles (cause);
565563 if (willShowSelectionHandles != _showSelectionHandles) {
566564 setState (() {
567565 _showSelectionHandles = willShowSelectionHandles;
568566 });
569567 }
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);
576570
577571 switch (Theme .of (context).platform) {
578572 case TargetPlatform .iOS:
Original file line number Diff line number Diff line change @@ -5367,4 +5367,43 @@ void main() {
53675367 final EditableText editableText = tester.widget (find.byType (EditableText ));
53685368 expect (editableText.style.fontSize, textStyle.fontSize);
53695369 });
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+ });
53705409}
You can’t perform that action at this time.
0 commit comments