Work around the crash by preventing deletes on -1,-1 selection (#73417)
This commit is contained in:
committed by
GitHub
parent
b65a235139
commit
fc27828c87
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user