diff --git a/java/src/org/futo/inputmethod/latin/LatinIME.kt b/java/src/org/futo/inputmethod/latin/LatinIME.kt index a54dddee9..6e32cdcec 100644 --- a/java/src/org/futo/inputmethod/latin/LatinIME.kt +++ b/java/src/org/futo/inputmethod/latin/LatinIME.kt @@ -45,6 +45,7 @@ import org.futo.inputmethod.latin.common.Constants import org.futo.inputmethod.latin.uix.BasicThemeProvider import org.futo.inputmethod.latin.uix.DynamicThemeProvider import org.futo.inputmethod.latin.uix.DynamicThemeProviderOwner +import org.futo.inputmethod.latin.uix.EmojiTracker.useEmoji import org.futo.inputmethod.latin.uix.SUGGESTION_BLACKLIST import org.futo.inputmethod.latin.uix.THEME_KEY import org.futo.inputmethod.latin.uix.UixManager @@ -537,4 +538,12 @@ class LatinIME : InputMethodService(), LifecycleOwner, ViewModelStoreOwner, Save refreshSuggestions() } + + fun rememberEmojiSuggestion(suggestion: SuggestedWordInfo) { + if(suggestion.mKindAndFlags == SuggestedWordInfo.KIND_EMOJI_SUGGESTION) { + lifecycleScope.launch { + useEmoji(suggestion.mWord) + } + } + } } \ No newline at end of file diff --git a/java/src/org/futo/inputmethod/latin/LatinIMELegacy.java b/java/src/org/futo/inputmethod/latin/LatinIMELegacy.java index 43cb0bbcc..4b0dcf947 100644 --- a/java/src/org/futo/inputmethod/latin/LatinIMELegacy.java +++ b/java/src/org/futo/inputmethod/latin/LatinIMELegacy.java @@ -1661,6 +1661,10 @@ public class LatinIMELegacy implements KeyboardActionListener, mKeyboardSwitcher.getCurrentKeyboardScriptId(), mHandler); updateStateAfterInputTransaction(completeInputTransaction); + + if(suggestionInfo.isKindOf(SuggestedWordInfo.KIND_EMOJI_SUGGESTION)) { + ((LatinIME)mInputMethodService).rememberEmojiSuggestion(suggestionInfo); + } } @Override diff --git a/java/src/org/futo/inputmethod/latin/uix/ActionBar.kt b/java/src/org/futo/inputmethod/latin/uix/ActionBar.kt index 8b786c375..9775e7ed5 100644 --- a/java/src/org/futo/inputmethod/latin/uix/ActionBar.kt +++ b/java/src/org/futo/inputmethod/latin/uix/ActionBar.kt @@ -68,6 +68,7 @@ import androidx.compose.ui.unit.sp import org.futo.inputmethod.latin.R import org.futo.inputmethod.latin.SuggestedWords import org.futo.inputmethod.latin.SuggestedWords.SuggestedWordInfo +import org.futo.inputmethod.latin.SuggestedWords.SuggestedWordInfo.KIND_EMOJI_SUGGESTION import org.futo.inputmethod.latin.SuggestedWords.SuggestedWordInfo.KIND_TYPED import org.futo.inputmethod.latin.suggestions.SuggestionStripView import org.futo.inputmethod.latin.uix.actions.ClipboardAction @@ -306,7 +307,7 @@ fun RowScope.SuggestionItems(words: SuggestedWords, onClick: (i: Int) -> Unit, o try { for(i in 0 until words.size()) { val info = words.getInfo(i) - if(info.mKindAndFlags == SuggestedWordInfo.KIND_EMOJI_SUGGESTION) { + if(info.mKindAndFlags == KIND_EMOJI_SUGGESTION && i > 2) { suggestionOrder[0] = i } } diff --git a/java/src/org/futo/inputmethod/latin/uix/EmojiTracker.kt b/java/src/org/futo/inputmethod/latin/uix/EmojiTracker.kt index dfbe9281d..4a6575248 100644 --- a/java/src/org/futo/inputmethod/latin/uix/EmojiTracker.kt +++ b/java/src/org/futo/inputmethod/latin/uix/EmojiTracker.kt @@ -18,7 +18,7 @@ object EmojiTracker { suspend fun Context.useEmoji(emoji: String) { dataStore.edit { val combined = emoji + "<|>" + (it[lastUsedEmoji] ?: "") - it[lastUsedEmoji] = combined.split("<|>").take(512).joinToString("<|>") + it[lastUsedEmoji] = combined.split("<|>").take(128).joinToString("<|>") } } diff --git a/java/src/org/futo/inputmethod/latin/uix/actions/EmojiAction.kt b/java/src/org/futo/inputmethod/latin/uix/actions/EmojiAction.kt index 59a9aed04..849153435 100644 --- a/java/src/org/futo/inputmethod/latin/uix/actions/EmojiAction.kt +++ b/java/src/org/futo/inputmethod/latin/uix/actions/EmojiAction.kt @@ -463,12 +463,25 @@ class PersistentEmojiState : PersistentActionState { } emojiAliases = HashMap().apply { + // Add absolute alias matches first (e.g. "joy") and only later put first-word tag/alias matches (e.g. "joy_cat") emojis.value!!.forEach { emoji -> - emoji.tags.forEach { put(it.split("_").first(), emoji) } - emoji.aliases.forEach { put(it.split("_").first(), emoji) } + emoji.aliases.forEach { + val x = it + if (!containsKey(x)) { + put(x, emoji) + } + } + } + + emojis.value!!.forEach { emoji -> + (emoji.tags + emoji.aliases).forEach { + val x = it.split("_").first() + if (!containsKey(x)) { + put(x, emoji) + } + } } } - } }