-
Notifications
You must be signed in to change notification settings - Fork 6k
fix flutter TextField delete emoji bug on android #7555
fix flutter TextField delete emoji bug on android #7555
Conversation
@@ -127,6 +127,16 @@ public boolean setSelection(int start, int end) { | |||
return result; | |||
} | |||
|
|||
private void deleteLastCharacter(int selStart, int selEnd) { | |||
String str = mEditable.toString(); | |||
//calc emoji chatacter length (most is 2,and it's can't deal with charactors whick too long) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will work for simple emojis, but will not work for something like 👨👩👧👧, which is made up of 4 16bit emoji codepoints as well as 3 8bit zero-width-joiner codepoints. This would do a similar thing to the current behavior, except it would cut off two emojis codepoints at a time.
I like the idea of handling this in the platform code though, as it is currently not (yet) possible to obtain the lengths of extended grapheme clusters in a dart string. We could potentially handle this here using java/obj-c APIs to obtain the full cluster length and avoid handling this problem in dart. I will see if this is possible in java/obj-c
Unfortunately, this does not fix the problem for many (most) emojis, and is only a hack for a subset of short emojis. I'm hesitant to introduce something like this if it does not address the full problem, and will encourage additional subset-hacks to be layered on top of this. In the dart code, we actually do something where we expand a search radius until we are covering a full extended grapheme cluster and GetBoxesForRange() begins to cover the next glyph. However, it is not clear to me if this is easily adaptable here. |
A simple algorithm based on https://docs.oracle.com/javase/8/docs/api/java/lang/CharSequence.html#codePoints-- might work for the android side. We may be able to loop through until no additional ZWJs are found, which could indicate the end of a grapheme cluster. I can look into this unless @XingXiaoGang you wanted to take a shot at it. |
Actually, I haven't been able to repro on master. flutter/flutter#24797 might have fixed this already. Can you verify you are running the latest engine and Flutter framework? the output of |
flutter/flutter#23496, flutter/flutter#26602, flutter/flutter#24802, flutter/flutter#13404 are some issues that look related. |
Let me verify that the cluster deletion bug is fixed. I remember I landed a fix for it but there was some wierdness around behavior on lines further down. |
@XingXiaoGang @GaryQian I have the same problem |
@yy1300326388 I have the same problem 我这个提交可以解决一分部这个问题,可以下载映客app,使用搜索功能查看效果。不过不是很完美,目前没时间继续跟进这个bug |
this pull request fix a bug, that is :
When use flutter TextField on android phones, input emoji, such as 😂😂😂,when tap delete, it can't delete integrated,it becomes "😂😂?"
@zoechi Hi ~ ,these issues are seems like the same:
flutter/flutter#24203
flutter/flutter#24203
.It works on my phone.