properly determine length of emojis when deleting

fixes issue described in https://github.com/Helium314/HeliBoard/issues/426#issuecomment-1944132643, but not the initial problem
This commit is contained in:
Helium314 2024-03-03 14:48:03 +01:00
parent fe5aa2c33c
commit 4b52f2d51d
5 changed files with 65 additions and 23 deletions

View file

@ -1046,6 +1046,14 @@ public final class RichInputConnection implements PrivateCommandPerformer {
return mCommittedTextBeforeComposingText.indexOf(" ") != -1;
}
public int getCharCountToDeleteBeforeCursor() {
final int lastCodePoint = getCodePointBeforeCursor();
if (!Character.isSupplementaryCodePoint(lastCodePoint)) return 1;
if (!StringUtils.mightBeEmoji(lastCodePoint)) return 2;
final String text = mCommittedTextBeforeComposingText.toString() + mComposingText;
return StringUtilsKt.getFullEmojiAtEnd(text).length();
}
public boolean hasLetterBeforeLastSpaceBeforeCursor() {
return StringUtilsKt.hasLetterBeforeLastSpaceBeforeCursor(mCommittedTextBeforeComposingText);
}