Skip to content

Commit 65496e4

Browse files
committed
fix(suggest): never autocorrect a typed word to an emoji
The emoji dictionary is part of the main dictionary collection, so a language with no word list still counts as having a main dictionary and auto-correct stays on, with emojis as possibly the only candidates. Exact personal dictionary shortcuts to an emoji still apply. Claude-Session: https://claude.ai/code/session_017YwBxUnnx3DqiiATw5XxUk
1 parent fb560da commit 65496e4

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

‎app/src/main/java/helium314/keyboard/latin/Suggest.kt‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,9 @@ class Suggest(private val mDictionaryFacilitator: DictionaryFacilitator) {
308308
|| (wordComposer.isMostlyCaps() && !wordComposer.isAllUpperCase()) // We never auto-correct when suggestions are resumed because it would be unexpected
309309
|| wordComposer.isResumed() // If we don't have a main dictionary, we never want to auto-correct. The reason
310310
|| isDeveloperTokenOrSpecialSyntax(consideredWord)
311+
// never replace a typed word with an emoji, unless the user mapped it as a shortcut. The emoji dictionary
312+
// is part of the main dictionary, so without a word list emojis can be the only candidates
313+
|| (firstSuggestionInContainer?.isEmoji == true && !isExactShortcut(firstSuggestionInContainer))
311314
// for this is, the user may have a contact whose name happens to match a valid
312315
// word in their language, and it will unexpectedly auto-correct. For example, if
313316
// the user types in English with no dictionary and has a "Will" in their contact

‎app/src/test/java/helium314/keyboard/latin/SuggestTest.kt‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,20 @@ class SuggestTest {
5252
.edit { putBoolean(Settings.PREF_AUTO_CORRECTION, true) } // need to enable, off by default
5353
}
5454

55+
// with only an emoji dictionary (no word list), emojis are the only candidates for any unknown word
56+
@Test fun `unknown word is not autocorrected to an emoji`() {
57+
val locale = Locale.ENGLISH
58+
val result = shouldBeAutoCorrected(
59+
"lov",
60+
listOf(suggestion("\uD83D\uDE0D", Int.MAX_VALUE, locale)),
61+
null,
62+
null,
63+
locale,
64+
thresholdVeryAggressive
65+
)
66+
assert(!result.last()) // should not be corrected
67+
}
68+
5569
@Test fun `'on' to 'in' if 'in' was used before in this context`() {
5670
val locale = Locale.ENGLISH
5771
val result = shouldBeAutoCorrected(

0 commit comments

Comments
 (0)