mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-16 23:12:47 +00:00
improve emoji detection when deleting
still has issues with hand + skin tone emojis
This commit is contained in:
parent
d91350524a
commit
6a34f2c832
3 changed files with 10 additions and 6 deletions
|
@ -1072,10 +1072,12 @@ public final class RichInputConnection implements PrivateCommandPerformer {
|
||||||
|
|
||||||
public int getCharCountToDeleteBeforeCursor() {
|
public int getCharCountToDeleteBeforeCursor() {
|
||||||
final int lastCodePoint = getCodePointBeforeCursor();
|
final int lastCodePoint = getCodePointBeforeCursor();
|
||||||
if (!Character.isSupplementaryCodePoint(lastCodePoint)) return 1;
|
if (StringUtils.mightBeEmoji(lastCodePoint)) {
|
||||||
if (!StringUtils.mightBeEmoji(lastCodePoint)) return 2;
|
final String text = mCommittedTextBeforeComposingText.toString() + mComposingText;
|
||||||
final String text = mCommittedTextBeforeComposingText.toString() + mComposingText;
|
final int emojiLength = StringUtilsKt.getFullEmojiAtEnd(text).length();
|
||||||
return StringUtilsKt.getFullEmojiAtEnd(text).length();
|
if (emojiLength > 0) return emojiLength;
|
||||||
|
}
|
||||||
|
return Character.isSupplementaryCodePoint(lastCodePoint) ? 2 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasLetterBeforeLastSpaceBeforeCursor() {
|
public boolean hasLetterBeforeLastSpaceBeforeCursor() {
|
||||||
|
|
|
@ -64,6 +64,8 @@ fun getFullEmojiAtEnd(s: CharSequence): String {
|
||||||
// stop if codepoint can't be emoji
|
// stop if codepoint can't be emoji
|
||||||
if (!mightBeEmoji(codepoint)) return ""
|
if (!mightBeEmoji(codepoint)) return ""
|
||||||
offset -= Character.charCount(codepoint)
|
offset -= Character.charCount(codepoint)
|
||||||
|
// todo: if codepoint in 0x1F3FB..0x1F3FF -> combine with other emojis in front, but only if they actually combine
|
||||||
|
// why isn't this done with zwj like everything else? skin tones can be emojis by themselves...
|
||||||
if (offset > 0 && text[offset - 1].code == KeyCode.ZWJ) {
|
if (offset > 0 && text[offset - 1].code == KeyCode.ZWJ) {
|
||||||
offset -= 1
|
offset -= 1
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -1311,7 +1311,7 @@ public final class InputLogic {
|
||||||
// TODO: Add a new StatsUtils method onBackspaceWhenNoText()
|
// TODO: Add a new StatsUtils method onBackspaceWhenNoText()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final int lengthToDelete = Character.isSupplementaryCodePoint(codePointBeforeCursor)
|
final int lengthToDelete = codePointBeforeCursor > 0xFE00
|
||||||
? mConnection.getCharCountToDeleteBeforeCursor() : 1;
|
? mConnection.getCharCountToDeleteBeforeCursor() : 1;
|
||||||
mConnection.deleteTextBeforeCursor(lengthToDelete);
|
mConnection.deleteTextBeforeCursor(lengthToDelete);
|
||||||
int totalDeletedLength = lengthToDelete;
|
int totalDeletedLength = lengthToDelete;
|
||||||
|
@ -1324,7 +1324,7 @@ public final class InputLogic {
|
||||||
final int codePointBeforeCursorToDeleteAgain =
|
final int codePointBeforeCursorToDeleteAgain =
|
||||||
mConnection.getCodePointBeforeCursor();
|
mConnection.getCodePointBeforeCursor();
|
||||||
if (codePointBeforeCursorToDeleteAgain != Constants.NOT_A_CODE) {
|
if (codePointBeforeCursorToDeleteAgain != Constants.NOT_A_CODE) {
|
||||||
final int lengthToDeleteAgain = Character.isSupplementaryCodePoint(codePointBeforeCursorToDeleteAgain)
|
final int lengthToDeleteAgain = codePointBeforeCursor > 0xFE00
|
||||||
? mConnection.getCharCountToDeleteBeforeCursor() : 1;
|
? mConnection.getCharCountToDeleteBeforeCursor() : 1;
|
||||||
mConnection.deleteTextBeforeCursor(lengthToDeleteAgain);
|
mConnection.deleteTextBeforeCursor(lengthToDeleteAgain);
|
||||||
totalDeletedLength += lengthToDeleteAgain;
|
totalDeletedLength += lengthToDeleteAgain;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue