fix: check text editing controlling, if selection is valid (#10868)

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou
2025-02-21 11:00:19 +08:00
committed by GitHub
parent 2575e14811
commit fc396d2166

View File

@@ -3706,11 +3706,11 @@ Widget workaroundWindowBorder(BuildContext context, Widget child) {
); );
} }
void updateTextAndPreserveSelection(TextEditingController controller, String text) { void updateTextAndPreserveSelection(
final preSelectionStart = controller.selection.start; TextEditingController controller, String text) {
final preSelectionEnd = controller.selection.end;
// Only care about select all for now. // Only care about select all for now.
final isSelected = preSelectionEnd > preSelectionStart; final isSelected = controller.selection.isValid &&
controller.selection.end > controller.selection.start;
// Set text will make the selection invalid. // Set text will make the selection invalid.
controller.text = text; controller.text = text;