mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-06-18 23:20:54 +00:00
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:
parent
fe5aa2c33c
commit
4b52f2d51d
5 changed files with 65 additions and 23 deletions
|
@ -1253,31 +1253,26 @@ public final class InputLogic {
|
|||
// TODO: Add a new StatsUtils method onBackspaceWhenNoText()
|
||||
return;
|
||||
}
|
||||
if (StringUtils.mightBeEmoji(codePointBeforeCursor)) {
|
||||
// emoji length varies, so we'd need to find out length to delete correctly
|
||||
// the solution is not optimal, but a reasonable workaround for issues when trying to delete emojis
|
||||
sendDownUpKeyEvent(KeyEvent.KEYCODE_DEL);
|
||||
} else {
|
||||
final int lengthToDelete = Character.isSupplementaryCodePoint(codePointBeforeCursor) ? 2 : 1;
|
||||
mConnection.deleteTextBeforeCursor(lengthToDelete);
|
||||
int totalDeletedLength = lengthToDelete;
|
||||
if (mDeleteCount > Constants.DELETE_ACCELERATE_AT) {
|
||||
// If this is an accelerated (i.e., double) deletion, then we need to
|
||||
// consider unlearning here because we may have already reached
|
||||
// the previous word, and will lose it after next deletion.
|
||||
hasUnlearnedWordBeingDeleted |= unlearnWordBeingDeleted(
|
||||
inputTransaction.getMSettingsValues(), currentKeyboardScript);
|
||||
final int codePointBeforeCursorToDeleteAgain =
|
||||
mConnection.getCodePointBeforeCursor();
|
||||
if (codePointBeforeCursorToDeleteAgain != Constants.NOT_A_CODE) {
|
||||
final int lengthToDeleteAgain = Character.isSupplementaryCodePoint(
|
||||
codePointBeforeCursorToDeleteAgain) ? 2 : 1;
|
||||
mConnection.deleteTextBeforeCursor(lengthToDeleteAgain);
|
||||
totalDeletedLength += lengthToDeleteAgain;
|
||||
}
|
||||
final int lengthToDelete = Character.isSupplementaryCodePoint(codePointBeforeCursor)
|
||||
? mConnection.getCharCountToDeleteBeforeCursor() : 1;
|
||||
mConnection.deleteTextBeforeCursor(lengthToDelete);
|
||||
int totalDeletedLength = lengthToDelete;
|
||||
if (mDeleteCount > Constants.DELETE_ACCELERATE_AT) {
|
||||
// If this is an accelerated (i.e., double) deletion, then we need to
|
||||
// consider unlearning here because we may have already reached
|
||||
// the previous word, and will lose it after next deletion.
|
||||
hasUnlearnedWordBeingDeleted |= unlearnWordBeingDeleted(
|
||||
inputTransaction.getMSettingsValues(), currentKeyboardScript);
|
||||
final int codePointBeforeCursorToDeleteAgain =
|
||||
mConnection.getCodePointBeforeCursor();
|
||||
if (codePointBeforeCursorToDeleteAgain != Constants.NOT_A_CODE) {
|
||||
final int lengthToDeleteAgain = Character.isSupplementaryCodePoint(codePointBeforeCursorToDeleteAgain)
|
||||
? mConnection.getCharCountToDeleteBeforeCursor() : 1;
|
||||
mConnection.deleteTextBeforeCursor(lengthToDeleteAgain);
|
||||
totalDeletedLength += lengthToDeleteAgain;
|
||||
}
|
||||
StatsUtils.onBackspacePressed(totalDeletedLength);
|
||||
}
|
||||
StatsUtils.onBackspacePressed(totalDeletedLength);
|
||||
}
|
||||
}
|
||||
if (!hasUnlearnedWordBeingDeleted) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue