mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-20 08:50:25 +00:00
improve emoji deletion
This commit is contained in:
parent
178654b0e9
commit
ffe7d81ebc
4 changed files with 45 additions and 26 deletions
|
@ -33,6 +33,7 @@ Changes:
|
|||
* Re-arranged comma-long-press-menu, https://github.com/Helium314/openboard/pull/7
|
||||
* Make Bengali spell check work, https://github.com/Helium314/openboard/pull/11
|
||||
* Fix azerty layout in landscape mode on tablets, https://github.com/openboard-team/openboard/pull/791
|
||||
* Improve issues with emoji deletion (still happens with delete gesture), https://github.com/Helium314/openboard/issues/22
|
||||
|
||||
Plan / to do:
|
||||
* ~upgrade dependencies~
|
||||
|
|
|
@ -40,6 +40,7 @@ import org.dslul.openboard.inputmethod.keyboard.internal.KeyDrawParams;
|
|||
import org.dslul.openboard.inputmethod.keyboard.internal.KeyVisualAttributes;
|
||||
import org.dslul.openboard.inputmethod.latin.R;
|
||||
import org.dslul.openboard.inputmethod.latin.common.Constants;
|
||||
import org.dslul.openboard.inputmethod.latin.common.StringUtils;
|
||||
import org.dslul.openboard.inputmethod.latin.settings.Settings;
|
||||
import org.dslul.openboard.inputmethod.latin.settings.SettingsValues;
|
||||
import org.dslul.openboard.inputmethod.latin.suggestions.MoreSuggestionsView;
|
||||
|
@ -464,7 +465,7 @@ public class KeyboardView extends View {
|
|||
// set key color only if not in emoji keyboard range
|
||||
if (keyboard != null
|
||||
&& (this.getClass() == MoreSuggestionsView.class ?
|
||||
!containsEmoji(key.getLabel()) : // doesn't contain emoji (all can happen in MoreSuggestionsView)
|
||||
!StringUtils.probablyContainsEmoji(key.getLabel()) : // doesn't contain emoji (all can happen in MoreSuggestionsView)
|
||||
(keyboard.mId.mElementId < 10 || keyboard.mId.mElementId > 26) // not showing emoji keyboard (no emojis visible on main keyboard otherwise)
|
||||
))
|
||||
paint.setColorFilter(keyTextColorFilter);
|
||||
|
@ -559,15 +560,6 @@ public class KeyboardView extends View {
|
|||
}
|
||||
}
|
||||
|
||||
private static boolean containsEmoji(String s) {
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
char c = s.charAt(i);
|
||||
if (!(c <= 0xD7FF || (c >= 0xE000 && c <= 0xFFFD) || (c >= 0x10000 && c <= 0x10FFFF)))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Draw popup hint "..." at the bottom right corner of the key.
|
||||
protected void drawKeyPopupHint(@Nonnull final Key key, @Nonnull final Canvas canvas,
|
||||
@Nonnull final Paint paint, @Nonnull final KeyDrawParams params) {
|
||||
|
|
|
@ -711,4 +711,24 @@ public final class StringUtils {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean probablyContainsEmoji(String s) {
|
||||
int offset = 0;
|
||||
int length = s.length();
|
||||
while (offset < length) {
|
||||
int c = Character.codePointAt(s, offset);
|
||||
if (probablyIsEmojiCodePoint(c))
|
||||
return true;
|
||||
offset += Character.charCount(c);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// seemingly arbitrary ranges taken from "somewhere on the internet"
|
||||
public static boolean probablyIsEmojiCodePoint(int c) {
|
||||
return (0x200D <= c && c <= 0x3299) // ??
|
||||
|| (0x1F004 <= c && c <= 0x1F251) // ??
|
||||
|| (0x1F300 <= c && c <= 0x1FFFF) // ??
|
||||
|| c == 0xFE0F; // variation selector emoji with color
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1187,6 +1187,11 @@ public final class InputLogic {
|
|||
}
|
||||
final int lengthToDelete =
|
||||
Character.isSupplementaryCodePoint(codePointBeforeCursor) ? 2 : 1;
|
||||
if (StringUtils.probablyIsEmojiCodePoint(codePointBeforeCursor)) {
|
||||
// emoji length varies, so we'd need to find out length to delete correctly
|
||||
// this is not optimal, but a reasonable workaround for issues when trying to delete emojis
|
||||
sendDownUpKeyEvent(KeyEvent.KEYCODE_DEL);
|
||||
} else {
|
||||
mConnection.deleteTextBeforeCursor(lengthToDelete);
|
||||
int totalDeletedLength = lengthToDelete;
|
||||
if (mDeleteCount > Constants.DELETE_ACCELERATE_AT) {
|
||||
|
@ -1207,6 +1212,7 @@ public final class InputLogic {
|
|||
StatsUtils.onBackspacePressed(totalDeletedLength);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!hasUnlearnedWordBeingDeleted) {
|
||||
// Consider unlearning the word being deleted (if we have not done so already).
|
||||
unlearnWordBeingDeleted(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue