@@ -12016,8 +12016,8 @@ testWidgets('Floating cursor ending with selection', (WidgetTester tester) async
12016
12016
EditableText .debugDeterministicCursor = true ;
12017
12017
final FocusNode focusNode = FocusNode ();
12018
12018
final GlobalKey key = GlobalKey ();
12019
- // Set it up so that there will be word-wrap.
12020
- final TextEditingController controller = TextEditingController (text: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' );
12019
+
12020
+ final TextEditingController controller = TextEditingController (text: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ\n 1234567890 ' );
12021
12021
controller.selection = const TextSelection .collapsed (offset: 0 );
12022
12022
await tester.pumpWidget (
12023
12023
MaterialApp (
@@ -12030,6 +12030,7 @@ testWidgets('Floating cursor ending with selection', (WidgetTester tester) async
12030
12030
cursorColor: Colors .blue,
12031
12031
backgroundCursorColor: Colors .grey,
12032
12032
cursorOpacityAnimates: true ,
12033
+ maxLines: 2 ,
12033
12034
),
12034
12035
),
12035
12036
);
@@ -12040,7 +12041,7 @@ testWidgets('Floating cursor ending with selection', (WidgetTester tester) async
12040
12041
state.updateFloatingCursor (RawFloatingCursorPoint (state: FloatingCursorDragState .Start , offset: Offset .zero));
12041
12042
await tester.pump ();
12042
12043
12043
- // The floating cursor should be drawn at the start of the line.
12044
+ // The cursor should be drawn at the start of the line.
12044
12045
expect (key.currentContext! .findRenderObject (), paints..rrect (
12045
12046
rrect: RRect .fromRectAndRadius (
12046
12047
const Rect .fromLTWH (0.5 , 1 , 3 , 12 ),
@@ -12051,7 +12052,7 @@ testWidgets('Floating cursor ending with selection', (WidgetTester tester) async
12051
12052
state.updateFloatingCursor (RawFloatingCursorPoint (state: FloatingCursorDragState .Update , offset: const Offset (50 , 0 )));
12052
12053
await tester.pump ();
12053
12054
12054
- // The floating cursor should be drawn somewhere in the middle of the line
12055
+ // The cursor should be drawn somewhere in the middle of the line
12055
12056
expect (key.currentContext! .findRenderObject (), paints..rrect (
12056
12057
rrect: RRect .fromRectAndRadius (
12057
12058
const Rect .fromLTWH (50.5 , 1 , 3 , 12 ),
@@ -12069,7 +12070,7 @@ testWidgets('Floating cursor ending with selection', (WidgetTester tester) async
12069
12070
state.updateFloatingCursor (RawFloatingCursorPoint (state: FloatingCursorDragState .Start , offset: Offset .zero));
12070
12071
await tester.pump ();
12071
12072
12072
- // The floating cursor should be drawn near to the previous position.
12073
+ // The cursor should be drawn near to the previous position.
12073
12074
// It's different because it's snapped to exactly between characters.
12074
12075
expect (key.currentContext! .findRenderObject (), paints..rrect (
12075
12076
rrect: RRect .fromRectAndRadius (
@@ -12081,7 +12082,7 @@ testWidgets('Floating cursor ending with selection', (WidgetTester tester) async
12081
12082
state.updateFloatingCursor (RawFloatingCursorPoint (state: FloatingCursorDragState .Update , offset: const Offset (- 56 , 0 )));
12082
12083
await tester.pump ();
12083
12084
12084
- // The floating cursor should be drawn at the start of the line.
12085
+ // The cursor should be drawn at the start of the line.
12085
12086
expect (key.currentContext! .findRenderObject (), paints..rrect (
12086
12087
rrect: RRect .fromRectAndRadius (
12087
12088
const Rect .fromLTWH (0.5 , 1 , 3 , 12 ),
@@ -12096,11 +12097,87 @@ testWidgets('Floating cursor ending with selection', (WidgetTester tester) async
12096
12097
state.updateFloatingCursor (RawFloatingCursorPoint (state: FloatingCursorDragState .End , offset: Offset .zero));
12097
12098
await tester.pump ();
12098
12099
12099
- // Selection should not be updated as the new position is within the selection range .
12100
+ // Selection should not be changed since it wasn't previously collapsed .
12100
12101
expect (controller.selection.isCollapsed, false );
12101
12102
expect (controller.selection.baseOffset, 0 );
12102
12103
expect (controller.selection.extentOffset, 4 );
12103
12104
12105
+ // Now test using keyboard selection in a forwards direction.
12106
+ controller.selection = const TextSelection .collapsed (offset: 0 );
12107
+ await tester.pump ();
12108
+ state.updateFloatingCursor (RawFloatingCursorPoint (state: FloatingCursorDragState .Start , offset: Offset .zero));
12109
+ await tester.pump ();
12110
+
12111
+ // The cursor should be drawn in the same (start) position.
12112
+ expect (key.currentContext! .findRenderObject (), paints..rrect (
12113
+ rrect: RRect .fromRectAndRadius (
12114
+ const Rect .fromLTWH (0.5 , 1 , 3 , 12 ),
12115
+ const Radius .circular (1 )
12116
+ )
12117
+ ));
12118
+
12119
+ state.updateFloatingCursor (RawFloatingCursorPoint (state: FloatingCursorDragState .Update , offset: const Offset (56 , 0 )));
12120
+ await tester.pump ();
12121
+
12122
+ // The cursor should be drawn somewhere in the middle of the line.
12123
+ expect (key.currentContext! .findRenderObject (), paints..rrect (
12124
+ rrect: RRect .fromRectAndRadius (
12125
+ const Rect .fromLTWH (56.5 , 1 , 3 , 12 ),
12126
+ const Radius .circular (1 )
12127
+ )
12128
+ ));
12129
+
12130
+ // Simulate UIKit setting the selection using keyboard selection.
12131
+ controller.selection = const TextSelection (baseOffset: 0 , extentOffset: 4 );
12132
+ await tester.pump ();
12133
+
12134
+ state.updateFloatingCursor (RawFloatingCursorPoint (state: FloatingCursorDragState .End , offset: Offset .zero));
12135
+ await tester.pump ();
12136
+
12137
+ // Selection should not be changed since it wasn't previously collapsed.
12138
+ expect (controller.selection.isCollapsed, false );
12139
+ expect (controller.selection.baseOffset, 0 );
12140
+ expect (controller.selection.extentOffset, 4 );
12141
+
12142
+ // Test that the affinity is updated in case the floating cursor ends at the same offset.
12143
+
12144
+ // Put the selection at the beginning of the second line.
12145
+ controller.selection = const TextSelection .collapsed (offset: 27 );
12146
+ await tester.pump ();
12147
+
12148
+ // Now test using keyboard selection in a forwards direction.
12149
+ state.updateFloatingCursor (RawFloatingCursorPoint (state: FloatingCursorDragState .Start , offset: Offset .zero));
12150
+ await tester.pump ();
12151
+
12152
+ // The cursor should be drawn at the start of the second line.
12153
+ expect (key.currentContext! .findRenderObject (), paints..rrect (
12154
+ rrect: RRect .fromRectAndRadius (
12155
+ const Rect .fromLTWH (0.5 , 15 , 3 , 12 ),
12156
+ const Radius .circular (1 )
12157
+ )
12158
+ ));
12159
+
12160
+ // Move the cursor to the end of the first line.
12161
+
12162
+ state.updateFloatingCursor (RawFloatingCursorPoint (state: FloatingCursorDragState .Update , offset: const Offset (9999 , - 14 )));
12163
+ await tester.pump ();
12164
+
12165
+ // The cursor should be drawn at the end of the first line.
12166
+ expect (key.currentContext! .findRenderObject (), paints..rrect (
12167
+ rrect: RRect .fromRectAndRadius (
12168
+ const Rect .fromLTWH (800.5 , 1 , 3 , 12 ),
12169
+ const Radius .circular (1 )
12170
+ )
12171
+ ));
12172
+
12173
+ state.updateFloatingCursor (RawFloatingCursorPoint (state: FloatingCursorDragState .End , offset: Offset .zero));
12174
+ await tester.pump ();
12175
+
12176
+ // Selection should be changed as it was previously collapsed.
12177
+ expect (controller.selection.isCollapsed, true );
12178
+ expect (controller.selection.baseOffset, 27 );
12179
+ expect (controller.selection.extentOffset, 27 );
12180
+
12104
12181
EditableText .debugDeterministicCursor = false ;
12105
12182
});
12106
12183
0 commit comments