Skip to content

Handle invalid selection in TextEditingActionTarget #90826

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 29, 2021

Conversation

justinmc
Copy link
Contributor

A crash was happening when delete was pressed on an invalid selection. It turns out that the methods in TextEditingActionTarget just assumed that the selection was always valid. This PR changes the relevant methods to return and do nothing when the selection is invalid.

Closes #90472

Detailed explanation

What was happening in #90472 is that when controller.text is assigned, it also sets the selection to -1,-1 (code). However, this invalid selection was getting set back to 0,0 on Mac only, so Mac did not experience the bug. The reason is that Mac is the only platform that sends an "ACK" response back to the framework after the framework sends a text editing update (added in flutter/engine#13702). The Mac engine received the -1,-1 selection, converted it to 0,0 because Mac doesn't support invalid selection, and then ACKed the 0,0 back to the framework, coincidentally avoiding the bug! On all other platforms, there was no ACK, they were stuck with the invalid selection, and the bug happened.

Detailed solution?

The root of the problem here is that the framework's use of -1,-1 selection continues to plague us. Long term, we'd like to either use null or get rid of invalid selection altogether. CC @LongCatIsLooong .

Also, it's strange the Mac is the only platform that ACKs text changes back to the framework. @gspencergoog Is that still a behavior that we need? I know flutter/engine#13702 is a few years old now.

@justinmc justinmc self-assigned this Sep 27, 2021
@flutter-dashboard flutter-dashboard bot added the framework flutter/packages/flutter repository. See also f: labels. label Sep 27, 2021
@google-cla google-cla bot added the cla: yes label Sep 27, 2021
@justinmc justinmc merged commit cf09d99 into flutter:master Sep 29, 2021
@justinmc justinmc deleted the invalid-selection-delete branch September 29, 2021 20:14
clocksmith pushed a commit to clocksmith/flutter that referenced this pull request Oct 29, 2021
Prevents bugs related to invalid (-1,-1) selection in keyboard shortcuts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

App crashes when cursor is at the front of TextField and backspace is pressed
2 participants