Remember selecting emoji suggestions, improve emoji alias picking

This commit is contained in:
Aleksandras Kostarevas 2024-03-18 12:32:15 -05:00
parent 10c08ebda6
commit efac63ac10
5 changed files with 32 additions and 5 deletions

View File

@ -45,6 +45,7 @@ import org.futo.inputmethod.latin.common.Constants
import org.futo.inputmethod.latin.uix.BasicThemeProvider import org.futo.inputmethod.latin.uix.BasicThemeProvider
import org.futo.inputmethod.latin.uix.DynamicThemeProvider import org.futo.inputmethod.latin.uix.DynamicThemeProvider
import org.futo.inputmethod.latin.uix.DynamicThemeProviderOwner 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.SUGGESTION_BLACKLIST
import org.futo.inputmethod.latin.uix.THEME_KEY import org.futo.inputmethod.latin.uix.THEME_KEY
import org.futo.inputmethod.latin.uix.UixManager import org.futo.inputmethod.latin.uix.UixManager
@ -537,4 +538,12 @@ class LatinIME : InputMethodService(), LifecycleOwner, ViewModelStoreOwner, Save
refreshSuggestions() refreshSuggestions()
} }
fun rememberEmojiSuggestion(suggestion: SuggestedWordInfo) {
if(suggestion.mKindAndFlags == SuggestedWordInfo.KIND_EMOJI_SUGGESTION) {
lifecycleScope.launch {
useEmoji(suggestion.mWord)
}
}
}
} }

View File

@ -1661,6 +1661,10 @@ public class LatinIMELegacy implements KeyboardActionListener,
mKeyboardSwitcher.getCurrentKeyboardScriptId(), mKeyboardSwitcher.getCurrentKeyboardScriptId(),
mHandler); mHandler);
updateStateAfterInputTransaction(completeInputTransaction); updateStateAfterInputTransaction(completeInputTransaction);
if(suggestionInfo.isKindOf(SuggestedWordInfo.KIND_EMOJI_SUGGESTION)) {
((LatinIME)mInputMethodService).rememberEmojiSuggestion(suggestionInfo);
}
} }
@Override @Override

View File

@ -68,6 +68,7 @@ import androidx.compose.ui.unit.sp
import org.futo.inputmethod.latin.R import org.futo.inputmethod.latin.R
import org.futo.inputmethod.latin.SuggestedWords import org.futo.inputmethod.latin.SuggestedWords
import org.futo.inputmethod.latin.SuggestedWords.SuggestedWordInfo 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.SuggestedWords.SuggestedWordInfo.KIND_TYPED
import org.futo.inputmethod.latin.suggestions.SuggestionStripView import org.futo.inputmethod.latin.suggestions.SuggestionStripView
import org.futo.inputmethod.latin.uix.actions.ClipboardAction import org.futo.inputmethod.latin.uix.actions.ClipboardAction
@ -306,7 +307,7 @@ fun RowScope.SuggestionItems(words: SuggestedWords, onClick: (i: Int) -> Unit, o
try { try {
for(i in 0 until words.size()) { for(i in 0 until words.size()) {
val info = words.getInfo(i) val info = words.getInfo(i)
if(info.mKindAndFlags == SuggestedWordInfo.KIND_EMOJI_SUGGESTION) { if(info.mKindAndFlags == KIND_EMOJI_SUGGESTION && i > 2) {
suggestionOrder[0] = i suggestionOrder[0] = i
} }
} }

View File

@ -18,7 +18,7 @@ object EmojiTracker {
suspend fun Context.useEmoji(emoji: String) { suspend fun Context.useEmoji(emoji: String) {
dataStore.edit { dataStore.edit {
val combined = emoji + "<|>" + (it[lastUsedEmoji] ?: "") val combined = emoji + "<|>" + (it[lastUsedEmoji] ?: "")
it[lastUsedEmoji] = combined.split("<|>").take(512).joinToString("<|>") it[lastUsedEmoji] = combined.split("<|>").take(128).joinToString("<|>")
} }
} }

View File

@ -463,12 +463,25 @@ class PersistentEmojiState : PersistentActionState {
} }
emojiAliases = HashMap<String, EmojiItem>().apply { emojiAliases = HashMap<String, EmojiItem>().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 -> emojis.value!!.forEach { emoji ->
emoji.tags.forEach { put(it.split("_").first(), emoji) } emoji.aliases.forEach {
emoji.aliases.forEach { put(it.split("_").first(), emoji) } 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)
}
}
} }
} }
} }
} }