Handle invalid selection in TextEditingActionTarget #90826
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 to0,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 to0,0
because Mac doesn't support invalid selection, and then ACKed the0,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 usenull
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.