Caret misplaced for emoji plus text #122477
Labels
a: text input
Entering text in a text field or keyboard related problems
framework
flutter/packages/flutter repository. See also f: labels.
P2
Important issues not at the top of the work list
If you type some text and then a complex emoji, the caret will stay at the start of the emoji rather than move to the end.
This resembles #50563, #98516, and #118403, but the symptoms are subtly different, and the fix is unrelated although it's in a nearby part of the code. (I'll be sending a PR with both fixes soon.)
Steps to Reproduce
Expected results:
The cursor (aka caret) moves to the end of each character you type.
All the text you type is shown in the order you typed it.
Actual results:
On typing the emoji, the cursor stays at the start of the emoji.
On typing more text, the cursor jumps back to the end. All the text you type is correctly shown in the order you typed it. So this shows that the underlying text input state knows the cursor should be at the end, and we're just painting it in the wrong place.
Repro details
In order to trigger the issue, the emoji's length in UTF-16 code units has to not be a power of 2: it has to be something other than 1, 2, 4, 8, etc. The simplest emoji are 1 or 2 code units long and don't trigger the issue. Most emoji that have a gender or skin-color modifier, or show a family or make other use of the zero-width joiner code point, do trigger the issue.
The repro may depend on the fonts you have on the device. I observe it on a Pixel 5 running Android 13, and on an iPhone 7 running iOS 15.
If you type "a👩🚀" or "ab👩🚀" instead of "abc👩🚀", then when you type the emoji, the behavior is still wrong but with a different symptom: the cursor will jump backward to the beginning, instead of staying at the start of the emoji. This symptom is caused by #50563.
Code sample
Video:
repro-emoji-text-caret.mp4
The text was updated successfully, but these errors were encountered: