From d57ea48ca1b7f60f549e7ade4b0d698509ca659a Mon Sep 17 00:00:00 2001 From: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com> Date: Wed, 22 May 2024 14:25:31 -0700 Subject: [PATCH] Remove an assert with false positives (#148795) Fixes https://github.com/flutter/flutter/issues/110343. This is not an important piece of guardrail and the iOS embedder only expects best-effort results anyways. --- .../lib/src/widgets/editable_text.dart | 1 - .../test/widgets/editable_text_test.dart | 31 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/widgets/editable_text.dart b/packages/flutter/lib/src/widgets/editable_text.dart index 069230666e9f..08487b5d2af0 100644 --- a/packages/flutter/lib/src/widgets/editable_text.dart +++ b/packages/flutter/lib/src/widgets/editable_text.dart @@ -4494,7 +4494,6 @@ class EditableTextState extends State with AutomaticKeepAliveClien Rect? composingRect = renderEditable.getRectForComposingRange(composingRange); // Send the caret location instead if there's no marked text yet. if (composingRect == null) { - assert(!composingRange.isValid || composingRange.isCollapsed); final int offset = composingRange.isValid ? composingRange.start : 0; composingRect = renderEditable.getLocalRectForCaret(TextPosition(offset: offset)); } diff --git a/packages/flutter/test/widgets/editable_text_test.dart b/packages/flutter/test/widgets/editable_text_test.dart index 8c031c4a17ff..ab260f8a3cf6 100644 --- a/packages/flutter/test/widgets/editable_text_test.dart +++ b/packages/flutter/test/widgets/editable_text_test.dart @@ -17548,6 +17548,37 @@ void main() { const TextSelection.collapsed(offset: 17, affinity: TextAffinity.upstream), ); }); + + testWidgets('Composing region can truncate grapheme', (WidgetTester tester) async { + await tester.pumpWidget( + MediaQuery( + data: const MediaQueryData(), + child: Directionality( + textDirection: TextDirection.ltr, + child: EditableText( + autofocus: true, + backgroundCursorColor: Colors.grey, + controller: controller, + focusNode: focusNode, + style: textStyle, + cursorColor: cursorColor, + ), + ), + ), + ); + + await tester.pumpAndSettle(); + assert(focusNode.hasFocus); + + controller.value = const TextEditingValue( + text: 'Á', + selection: TextSelection(baseOffset: 1, extentOffset: 2), + composing: TextSelection(baseOffset: 1, extentOffset: 2), + ); + await tester.pumpAndSettle(); + + expect(tester.takeException(), isNull); + }); } class UnsettableController extends TextEditingController {