Unverified Commit 21efdff8 authored by chunhtai's avatar chunhtai Committed by GitHub

fix issue 32212 Text field keyboard selection crashes (#32256)

parent c27d10bf
......@@ -428,7 +428,7 @@ class RenderEditable extends RenderBox {
int _handleHorizontalArrows(bool rightArrow, bool leftArrow, bool shift, int newOffset) {
// Set the new offset to be +/- 1 depending on which arrow is pressed
// If shift is down, we also want to update the previous cursor location
if (rightArrow && _extentOffset < text.text.length) {
if (rightArrow && _extentOffset < text.toPlainText().length) {
newOffset += 1;
if (shift)
_previousCursorLocation += 1;
......
......@@ -2973,6 +2973,23 @@ void main() {
expect(controller.selection.extentOffset - controller.selection.baseOffset, 1);
});
testWidgets('Shift test 2', (WidgetTester tester) async {
await setupWidget(tester);
const String testValue = 'abcdefghi';
await tester.showKeyboard(find.byType(TextField));
tester.testTextInput.updateEditingValue(const TextEditingValue(
text: testValue,
selection: TextSelection.collapsed(offset: 3),
composing: TextRange(start: 0, end: testValue.length)
));
await tester.pump();
sendKeyEventWithCode(22, true, true, false);
await tester.pumpAndSettle();
expect(controller.selection.extentOffset - controller.selection.baseOffset, 1);
});
testWidgets('Control Shift test', (WidgetTester tester) async {
await setupWidget(tester);
const String testValue = 'their big house';
......
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