diff --git a/app/src/main/java/helium314/keyboard/latin/Suggest.kt b/app/src/main/java/helium314/keyboard/latin/Suggest.kt index ac0856c8d..45c3e07fa 100644 --- a/app/src/main/java/helium314/keyboard/latin/Suggest.kt +++ b/app/src/main/java/helium314/keyboard/latin/Suggest.kt @@ -115,13 +115,16 @@ class Suggest(private val mDictionaryFacilitator: DictionaryFacilitator) { inputStyleIfNotPrediction } - if (hasAutoCorrection) { - // make sure typed word is shown, so user is able to override incoming autocorrection + // If there is an incoming autocorrection, make sure typed word is shown, so user is able to override it. + // Otherwise, if the relevant setting is enabled, show the typed word in the middle. + val indexOfTypedWord = if (hasAutoCorrection) 2 else 1 + if ((hasAutoCorrection || Settings.getInstance().current.mCenterSuggestionTextToCommit) + && suggestionsList.size >= indexOfTypedWord && !TextUtils.isEmpty(typedWordString)) { if (typedWordFirstOccurrenceWordInfo != null) { if (SuggestionStripView.DEBUG_SUGGESTIONS) addDebugInfo(typedWordFirstOccurrenceWordInfo, typedWordString) - suggestionsList.add(2, typedWordFirstOccurrenceWordInfo) + suggestionsList.add(indexOfTypedWord, typedWordFirstOccurrenceWordInfo) } else { - suggestionsList.add(2, + suggestionsList.add(indexOfTypedWord, SuggestedWordInfo(typedWordString, "", 0, SuggestedWordInfo.KIND_TYPED, Dictionary.DICTIONARY_USER_TYPED, SuggestedWordInfo.NOT_AN_INDEX, SuggestedWordInfo.NOT_A_CONFIDENCE) ) diff --git a/app/src/main/java/helium314/keyboard/latin/settings/CorrectionSettingsFragment.java b/app/src/main/java/helium314/keyboard/latin/settings/CorrectionSettingsFragment.java index 6cb03d803..08b4346ff 100644 --- a/app/src/main/java/helium314/keyboard/latin/settings/CorrectionSettingsFragment.java +++ b/app/src/main/java/helium314/keyboard/latin/settings/CorrectionSettingsFragment.java @@ -76,6 +76,7 @@ public final class CorrectionSettingsFragment extends SubScreenFragment setPreferenceVisible(Settings.PREF_MORE_AUTO_CORRECTION, Settings.readAutoCorrectEnabled(getSharedPreferences())); setPreferenceVisible(Settings.PREF_ADD_TO_PERSONAL_DICTIONARY, getSharedPreferences().getBoolean(Settings.PREF_KEY_USE_PERSONALIZED_DICTS, true)); setPreferenceVisible(Settings.PREF_ALWAYS_SHOW_SUGGESTIONS, getSharedPreferences().getBoolean(Settings.PREF_SHOW_SUGGESTIONS, true)); + setPreferenceVisible(Settings.PREF_CENTER_SUGGESTION_TEXT_TO_ENTER, getSharedPreferences().getBoolean(Settings.PREF_SHOW_SUGGESTIONS, true)); turnOffLookupContactsIfNoPermission(); } diff --git a/app/src/main/java/helium314/keyboard/latin/settings/Settings.java b/app/src/main/java/helium314/keyboard/latin/settings/Settings.java index 4565001f8..54b1116cf 100644 --- a/app/src/main/java/helium314/keyboard/latin/settings/Settings.java +++ b/app/src/main/java/helium314/keyboard/latin/settings/Settings.java @@ -87,6 +87,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang public static final String PREF_AUTO_CORRECTION = "auto_correction"; public static final String PREF_MORE_AUTO_CORRECTION = "more_auto_correction"; public static final String PREF_AUTO_CORRECTION_CONFIDENCE = "auto_correction_confidence"; + public static final String PREF_CENTER_SUGGESTION_TEXT_TO_ENTER = "center_suggestion_text_to_enter"; public static final String PREF_SHOW_SUGGESTIONS = "show_suggestions"; public static final String PREF_ALWAYS_SHOW_SUGGESTIONS = "always_show_suggestions"; public static final String PREF_KEY_USE_PERSONALIZED_DICTS = "use_personalized_dicts"; @@ -287,6 +288,10 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang res.getString(R.string.auto_correction_threshold_mode_index_modest)); } + public static boolean readCenterSuggestionTextToEnter(final SharedPreferences prefs, final Resources res) { + return prefs.getBoolean(PREF_CENTER_SUGGESTION_TEXT_TO_ENTER, res.getBoolean(R.bool.config_center_suggestion_text_to_enter)); + } + public static boolean readBlockPotentiallyOffensive(final SharedPreferences prefs, final Resources res) { return prefs.getBoolean(PREF_BLOCK_POTENTIALLY_OFFENSIVE, res.getBoolean(R.bool.config_block_potentially_offensive)); diff --git a/app/src/main/java/helium314/keyboard/latin/settings/SettingsValues.java b/app/src/main/java/helium314/keyboard/latin/settings/SettingsValues.java index 111a67c6f..f64e4a905 100644 --- a/app/src/main/java/helium314/keyboard/latin/settings/SettingsValues.java +++ b/app/src/main/java/helium314/keyboard/latin/settings/SettingsValues.java @@ -87,6 +87,7 @@ public class SettingsValues { public final List mPopupKeyLabelSources; public final List mSecondaryLocales; public final boolean mBigramPredictionEnabled;// Use bigrams to predict the next word when there is no input for it yet + public final boolean mCenterSuggestionTextToEnter; public final boolean mGestureInputEnabled; public final boolean mGestureTrailEnabled; public final boolean mGestureFloatingPreviewTextEnabled; @@ -161,6 +162,7 @@ public class SettingsValues { mAutoCorrectEnabled = mAutoCorrectionEnabledPerUserSettings && (mInputAttributes.mInputTypeShouldAutoCorrect || Settings.readMoreAutoCorrectEnabled(prefs)) && (mUrlDetectionEnabled || !InputTypeUtils.isUriOrEmailType(mInputAttributes.mInputType)); + mCenterSuggestionTextToEnter = Settings.readCenterSuggestionTextToEnter(prefs, res); mAutoCorrectionThreshold = mAutoCorrectEnabled ? readAutoCorrectionThreshold(res, prefs) : AUTO_CORRECTION_DISABLED_THRESHOLD; diff --git a/app/src/main/res/values/config-common.xml b/app/src/main/res/values/config-common.xml index f8c4abc2d..b2b52e1d1 100644 --- a/app/src/main/res/values/config-common.xml +++ b/app/src/main/res/values/config-common.xml @@ -6,6 +6,8 @@ --> + + false true diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e1ce7785b..4823cf74b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -124,6 +124,10 @@ Aggressive Very aggressive + + Always use middle suggestion + + On pressing space or punctuation, the middle suggestion will be entered Next-word suggestions diff --git a/app/src/main/res/xml/prefs_screen_correction.xml b/app/src/main/res/xml/prefs_screen_correction.xml index 2723e90a7..0edb993cf 100644 --- a/app/src/main/res/xml/prefs_screen_correction.xml +++ b/app/src/main/res/xml/prefs_screen_correction.xml @@ -101,6 +101,13 @@ android:defaultValue="true" android:persistent="true" /> + +