Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

fix flutter TextField delete emoji bug on android #7555

Closed
wants to merge 3 commits into from
Closed

fix flutter TextField delete emoji bug on android #7555

wants to merge 3 commits into from

Conversation

XingXiaoGang
Copy link

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.

@cbracken cbracken requested review from GaryQian and xster February 11, 2019 18:53
@cbracken
Copy link
Member

@xster @GaryQian can you review?

@@ -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)
Copy link
Contributor

@GaryQian GaryQian Feb 11, 2019

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

@GaryQian
Copy link
Contributor

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.

@GaryQian
Copy link
Contributor

GaryQian commented Feb 11, 2019

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.

@GaryQian
Copy link
Contributor

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 doctor is helpful.

@zoechi
Copy link

zoechi commented Feb 12, 2019

flutter/flutter#23496, flutter/flutter#26602, flutter/flutter#24802, flutter/flutter#13404 are some issues that look related.
@GaryQuian do you think they can be closed as well?

@GaryQian
Copy link
Contributor

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.

@BytesZero
Copy link

@XingXiaoGang @GaryQian I have the same problem

@XingXiaoGang
Copy link
Author

@yy1300326388 I have the same problem

我这个提交可以解决一分部这个问题,可以下载映客app,使用搜索功能查看效果。不过不是很完美,目前没时间继续跟进这个bug

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants