Skip to content

Commit

Permalink
Remove an assert with false positives (#148795)
Browse files Browse the repository at this point in the history
Fixes flutter/flutter#110343.

This is not an important piece of guardrail and the iOS embedder only expects best-effort results anyways.
  • Loading branch information
LongCatIsLooong authored May 22, 2024
1 parent b2eda06 commit d57ea48
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
1 change: 0 additions & 1 deletion packages/flutter/lib/src/widgets/editable_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4494,7 +4494,6 @@ class EditableTextState extends State<EditableText> 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));
}
Expand Down
31 changes: 31 additions & 0 deletions packages/flutter/test/widgets/editable_text_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit d57ea48

Please sign in to comment.