@@ -4,6 +4,7 @@ import 'package:flutter_test/flutter_test.dart';
4
4
import 'package:flutter_test_robots/flutter_test_robots.dart' ;
5
5
import 'package:flutter_test_runners/flutter_test_runners.dart' ;
6
6
import 'package:super_editor/super_editor.dart' ;
7
+ import 'package:super_text_layout/super_text_layout.dart' ;
7
8
8
9
import 'super_textfield_inspector.dart' ;
9
10
import 'super_textfield_robot.dart' ;
@@ -318,6 +319,73 @@ void main() {
318
319
'before after' ,
319
320
);
320
321
});
322
+
323
+ testWidgetsOnAllPlatforms ('selects inline widget upon double tap' , (tester) async {
324
+ // This test ensures that SuperTextField does not crash upon double tap
325
+ // when there is an inline widget in the text.
326
+ // See https://github.com/superlistapp/super_editor/issues/2611 for more details.
327
+
328
+ final controller = AttributedTextEditingController (
329
+ text: AttributedText (
330
+ '< inline' ,
331
+ null ,
332
+ {
333
+ 0 : const _NamedPlaceHolder ('1' ),
334
+ },
335
+ ),
336
+ );
337
+
338
+ await _pumpTestApp (tester, controller: controller);
339
+
340
+ // Double tap at the inline widget.
341
+ final inlineWidgetCenter = tester.getCenter (find.byPlaceholderName ('1' ));
342
+ await tester.tapAt (inlineWidgetCenter);
343
+ await tester.pump (kDoubleTapMinTime);
344
+ await tester.tapAt (inlineWidgetCenter);
345
+ // Wait for the double tap to be recognized.
346
+ await tester.pump (kTapMinTime);
347
+
348
+ // Ensure the inline widget was selected.
349
+ expect (
350
+ SuperTextFieldInspector .findSelection (),
351
+ const TextSelection (baseOffset: 0 , extentOffset: 1 ),
352
+ );
353
+ });
354
+
355
+ testWidgetsOnAllPlatforms ('does not invalidate layout when selection changes' , (tester) async {
356
+ final controller = AttributedTextEditingController (
357
+ text: AttributedText (
358
+ 'Hello' ,
359
+ null ,
360
+ {
361
+ 5 : const _NamedPlaceHolder ('1' ),
362
+ },
363
+ ),
364
+ );
365
+
366
+ await _pumpTestApp (tester, controller: controller);
367
+
368
+ // Place the caret at the beginning of the textfield.
369
+ await tester.placeCaretInSuperTextField (0 );
370
+
371
+ // Keep track of whether of not the layout was invalidated.
372
+ bool wasLayoutInvalidated = false ;
373
+
374
+ final renderParagraph = find
375
+ .byType (LayoutAwareRichText ) //
376
+ .evaluate ()
377
+ .first
378
+ .findRenderObject () as RenderLayoutAwareParagraph ;
379
+ renderParagraph.onMarkNeedsLayout = () {
380
+ wasLayoutInvalidated = true ;
381
+ };
382
+
383
+ // Place the selection somewhere else.
384
+ await tester.placeCaretInSuperTextField (1 );
385
+
386
+ // Ensure the layout was not invalidated.
387
+ expect (wasLayoutInvalidated, isFalse);
388
+ });
321
389
});
322
390
}
323
391
0 commit comments