From f3b6505f14525b5a20826efc7bce37ae3727364f Mon Sep 17 00:00:00 2001 From: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com> Date: Tue, 2 Jan 2024 16:11:18 -0800 Subject: [PATCH] Fix 139196 selection OOB (#140300) Fixes #139196 --- packages/flutter/lib/src/widgets/editable_text.dart | 11 ++++++++++- .../test/widgets/editable_text_shortcuts_test.dart | 8 ++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/widgets/editable_text.dart b/packages/flutter/lib/src/widgets/editable_text.dart index 718b942988..73817d2de0 100644 --- a/packages/flutter/lib/src/widgets/editable_text.dart +++ b/packages/flutter/lib/src/widgets/editable_text.dart @@ -4742,6 +4742,15 @@ class EditableTextState extends State with AutomaticKeepAliveClien } void _updateSelection(UpdateSelectionIntent intent) { + assert( + intent.newSelection.start <= intent.currentTextEditingValue.text.length, + 'invalid selection: ${intent.newSelection}: it must not exceed the current text length ${intent.currentTextEditingValue.text.length}', + ); + assert( + intent.newSelection.end <= intent.currentTextEditingValue.text.length, + 'invalid selection: ${intent.newSelection}: it must not exceed the current text length ${intent.currentTextEditingValue.text.length}', + ); + bringIntoView(intent.newSelection.extent); userUpdateTextEditingValue( intent.currentTextEditingValue.copyWith(selection: intent.newSelection), @@ -5645,7 +5654,7 @@ class _UpdateTextSelectionVerticallyAction