From fe59a598b7f8766f0662c15d5f001cd1ce92ba1d Mon Sep 17 00:00:00 2001 From: Helium314 Date: Thu, 13 Feb 2025 18:08:34 +0100 Subject: [PATCH] fix potential issue with not set autocorrect threshold and an unintentionally changed default --- app/src/main/java/helium314/keyboard/latin/LatinIME.java | 8 ++------ .../java/helium314/keyboard/latin/settings/Defaults.kt | 2 +- .../keyboard/latin/utils/AutoCorrectionUtils.java | 2 +- .../test/java/helium314/keyboard/latin/SuggestTest.kt | 9 +++------ 4 files changed, 7 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/latin/LatinIME.java b/app/src/main/java/helium314/keyboard/latin/LatinIME.java index 80f402b49..647c0eea6 100644 --- a/app/src/main/java/helium314/keyboard/latin/LatinIME.java +++ b/app/src/main/java/helium314/keyboard/latin/LatinIME.java @@ -691,9 +691,7 @@ public class LatinIME extends InputMethodService implements mDictionaryFacilitator.resetDictionaries(this, locale, settingsValues.mUseContactsDictionary, settingsValues.mUsePersonalizedDicts, false, settingsValues.mAccount, "", this); - if (settingsValues.mAutoCorrectEnabled) { - mInputLogic.mSuggest.setAutoCorrectionThreshold(settingsValues.mAutoCorrectionThreshold); - } + mInputLogic.mSuggest.setAutoCorrectionThreshold(settingsValues.mAutoCorrectionThreshold); } /** @@ -1017,9 +1015,7 @@ public class LatinIME extends InputMethodService implements if (isDifferentTextField) { mainKeyboardView.closing(); - if (currentSettingsValues.mAutoCorrectEnabled) { - suggest.setAutoCorrectionThreshold(currentSettingsValues.mAutoCorrectionThreshold); - } + suggest.setAutoCorrectionThreshold(currentSettingsValues.mAutoCorrectionThreshold); switcher.loadKeyboard(editorInfo, currentSettingsValues, getCurrentAutoCapsState(), getCurrentRecapitalizeState()); if (needToCallLoadKeyboardLater) { // If we need to call loadKeyboard again later, we need to save its state now. The diff --git a/app/src/main/java/helium314/keyboard/latin/settings/Defaults.kt b/app/src/main/java/helium314/keyboard/latin/settings/Defaults.kt index b0d5eb99f..44e502dcd 100644 --- a/app/src/main/java/helium314/keyboard/latin/settings/Defaults.kt +++ b/app/src/main/java/helium314/keyboard/latin/settings/Defaults.kt @@ -45,7 +45,7 @@ object Defaults { const val PREF_AUTO_CORRECTION = true const val PREF_MORE_AUTO_CORRECTION = false const val PREF_AUTO_CORRECTION_CONFIDENCE = "0" - const val PREF_AUTOCORRECT_SHORTCUTS = false + const val PREF_AUTOCORRECT_SHORTCUTS = true const val PREF_CENTER_SUGGESTION_TEXT_TO_ENTER = false const val PREF_SHOW_SUGGESTIONS = true const val PREF_ALWAYS_SHOW_SUGGESTIONS = false diff --git a/app/src/main/java/helium314/keyboard/latin/utils/AutoCorrectionUtils.java b/app/src/main/java/helium314/keyboard/latin/utils/AutoCorrectionUtils.java index 8ebee14ec..86da88049 100644 --- a/app/src/main/java/helium314/keyboard/latin/utils/AutoCorrectionUtils.java +++ b/app/src/main/java/helium314/keyboard/latin/utils/AutoCorrectionUtils.java @@ -36,7 +36,7 @@ public final class AutoCorrectionUtils { if (DebugFlags.DEBUG_ENABLED) { Log.d(TAG, "Normalized " + consideredWord + "," + suggestion + "," + autoCorrectionSuggestionScore + ", " + normalizedScore - + "(" + threshold + ")"); + + " (" + threshold + ")"); } if (normalizedScore >= threshold) { if (DebugFlags.DEBUG_ENABLED) { diff --git a/app/src/test/java/helium314/keyboard/latin/SuggestTest.kt b/app/src/test/java/helium314/keyboard/latin/SuggestTest.kt index 6b3452756..e0b11d104 100644 --- a/app/src/test/java/helium314/keyboard/latin/SuggestTest.kt +++ b/app/src/test/java/helium314/keyboard/latin/SuggestTest.kt @@ -268,11 +268,6 @@ class SuggestTest { assert(!result.last()) // should not be corrected } - private fun setAutCorrectThreshold(threshold: String) { - val prefs = latinIME.prefs() - prefs.edit { putString(Settings.PREF_AUTO_CORRECTION_CONFIDENCE, threshold) } - } - private fun shouldBeAutoCorrected(word: String, // typed word suggestions: List, // suggestions ordered by score, including suggestion for typed word if in dictionary firstSuggestionForEmpty: SuggestedWordInfo?, // first suggestion if typed word would be empty (null if none) @@ -280,7 +275,9 @@ class SuggestTest { typingLocale: Locale, // used for checking whether suggestion locale is the same, relevant e.g. for English i -> I shortcut, but we want Polish i autoCorrectThreshold: String // 0, 1, or 2, but better use the vals on top with the corresponding name ): List { - setAutCorrectThreshold(autoCorrectThreshold) + latinIME.prefs().edit { putString(Settings.PREF_AUTO_CORRECTION_CONFIDENCE, autoCorrectThreshold) } + // enable "more autocorrect" so we actually have autocorrect even though we don't set a compatible input type + latinIME.prefs().edit { putBoolean(Settings.PREF_MORE_AUTO_CORRECTION, true) } currentTypingLocale = typingLocale val suggestionsContainer = ArrayList().apply { addAll(suggestions) } val suggestionResults = SuggestionResults(suggestions.size, false, false)