You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 500fc64
Browse filesBrowse the repository at this point in the historyBrowse files
common: Fix surrogate pair stepping in TextInputModel
Fixes surrogate pair stepping in `DeleteSurrounding`, `Delete`, and
`Backspace`. This is not my first rodeo: flutter-team-archive/engine#3590.
Walking forward over the characters to delete was measuring each one
against `text_.at(start)` rather than `text_.at(end)`, so after the
first step we kept re-reading the character we started from. That
over-deletes when the first character is a surrogate pair, and splits
the pair when a later one is, leaving an unpaired surrogate in `text_`
that `GetText` then can't convert, resulting in a range error.
This also limits both ends of the deletion to the editable range. We
need to protect against a surrogate pair that straddles the boundary.
We now stop the walk at the boundary rather than step past it. `start`
is clamped on entry because the selection is not required to sit inside
the composing range either. `SetComposingRange` accepts a cursor offset
that could place the caret beyond the range's end. Without this, `start`
could exceed `end` and underflow `deleted_length`, which erases the rest
of the buffer and wraps the composing range, or index out of bounds and
blow up.
Extracted helpers rather than copy-pasting even more than we already
had.
Spotted which working on: flutter#190704
0 commit comments