Unverified Commit fc27828c authored by Justin McCandless's avatar Justin McCandless Committed by GitHub

Work around the crash by preventing deletes on -1,-1 selection (#73417)

parent b65a2351
......@@ -825,7 +825,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
final TextSelection selection = textSelectionDelegate.textEditingValue.selection;
final String text = textSelectionDelegate.textEditingValue.text;
assert(_selection != null);
if (_readOnly) {
if (_readOnly || !selection.isValid) {
return;
}
String textBefore = selection.textBefore(text);
......
......@@ -6917,6 +6917,47 @@ void main() {
expect(error.toString(), contains(errorText));
});
});
// Regression test for https://github.com/flutter/flutter/issues/72400.
testWidgets("delete doesn't cause crash when selection is -1,-1", (WidgetTester tester) async {
final UnsettableController unsettableController = UnsettableController();
await tester.pumpWidget(
MediaQuery(
data: const MediaQueryData(devicePixelRatio: 1.0),
child: Directionality(
textDirection: TextDirection.ltr,
child: EditableText(
autofocus: true,
controller: unsettableController,
backgroundCursorColor: Colors.grey,
focusNode: focusNode,
style: textStyle,
cursorColor: cursorColor,
),
),
),
);
await tester.pump(); // Wait for the autofocus to take effect.
// Delete
await sendKeys(
tester,
<LogicalKeyboardKey>[
LogicalKeyboardKey.delete,
],
platform: 'android',
);
expect(tester.takeException(), null);
});
}
class UnsettableController extends TextEditingController {
@override
set value(TextEditingValue v) {
// Do nothing for set, which causes selection to remain as -1, -1.
}
}
class MockTextFormatter extends TextInputFormatter {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment