From 648ad1f508836b8240038fabd7a125010f9b71ae Mon Sep 17 00:00:00 2001 From: codokie <@> Date: Thu, 11 Apr 2024 00:25:30 +0300 Subject: [PATCH 1/2] (autocorrect) text to be committed is the middle suggestion --- .../main/java/helium314/keyboard/latin/Suggest.kt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/latin/Suggest.kt b/app/src/main/java/helium314/keyboard/latin/Suggest.kt index ac0856c8d..53337d39b 100644 --- a/app/src/main/java/helium314/keyboard/latin/Suggest.kt +++ b/app/src/main/java/helium314/keyboard/latin/Suggest.kt @@ -115,13 +115,15 @@ 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 no autocorrection, and autocorrection setting is enabled, show the typed word in the middle. + // If there is an incoming autocorrection, make sure typed word is shown, so user is able to override it. + val typedIndex = if (hasAutoCorrection) 2 else 1 + if (Settings.getInstance().current.mAutoCorrectEnabled && suggestionsList.size >= typedIndex) { if (typedWordFirstOccurrenceWordInfo != null) { if (SuggestionStripView.DEBUG_SUGGESTIONS) addDebugInfo(typedWordFirstOccurrenceWordInfo, typedWordString) - suggestionsList.add(2, typedWordFirstOccurrenceWordInfo) - } else { - suggestionsList.add(2, + suggestionsList.add(typedIndex, typedWordFirstOccurrenceWordInfo) + } else if (typedWordString.isNotEmpty()){ + suggestionsList.add(typedIndex, SuggestedWordInfo(typedWordString, "", 0, SuggestedWordInfo.KIND_TYPED, Dictionary.DICTIONARY_USER_TYPED, SuggestedWordInfo.NOT_AN_INDEX, SuggestedWordInfo.NOT_A_CONFIDENCE) ) From 17b67f9345b0217ff4bfbf069f72e920987fabe8 Mon Sep 17 00:00:00 2001 From: codokie <@> Date: Thu, 11 Apr 2024 13:53:07 +0300 Subject: [PATCH 2/2] Added setting --- app/src/main/java/helium314/keyboard/latin/Suggest.kt | 7 ++++--- .../latin/settings/CorrectionSettingsFragment.java | 1 + .../java/helium314/keyboard/latin/settings/Settings.java | 5 +++++ .../helium314/keyboard/latin/settings/SettingsValues.java | 2 ++ app/src/main/res/values/config-common.xml | 2 ++ app/src/main/res/values/strings.xml | 4 ++++ app/src/main/res/xml/prefs_screen_correction.xml | 7 +++++++ 7 files changed, 25 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/latin/Suggest.kt b/app/src/main/java/helium314/keyboard/latin/Suggest.kt index 53337d39b..f65410141 100644 --- a/app/src/main/java/helium314/keyboard/latin/Suggest.kt +++ b/app/src/main/java/helium314/keyboard/latin/Suggest.kt @@ -115,14 +115,15 @@ class Suggest(private val mDictionaryFacilitator: DictionaryFacilitator) { inputStyleIfNotPrediction } - // If there is no autocorrection, and autocorrection setting is enabled, show the typed word in the middle. // 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 typedIndex = if (hasAutoCorrection) 2 else 1 - if (Settings.getInstance().current.mAutoCorrectEnabled && suggestionsList.size >= typedIndex) { + if ((hasAutoCorrection || Settings.getInstance().current.mCenterSuggestionTextToCommit) + && suggestionsList.size >= typedIndex && !TextUtils.isEmpty(typedWordString)) { if (typedWordFirstOccurrenceWordInfo != null) { if (SuggestionStripView.DEBUG_SUGGESTIONS) addDebugInfo(typedWordFirstOccurrenceWordInfo, typedWordString) suggestionsList.add(typedIndex, typedWordFirstOccurrenceWordInfo) - } else if (typedWordString.isNotEmpty()){ + } else { suggestionsList.add(typedIndex, 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..4c6bfd35e 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 @@ private void refreshEnabledSettings() { 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_COMMIT, 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..0b23b1684 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_COMMIT = "center_suggestion_text_to_commit"; 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 static String readAutoCorrectConfidence(final SharedPreferences prefs, fi res.getString(R.string.auto_correction_threshold_mode_index_modest)); } + public static boolean readCenterSuggestionTextToCommit(final SharedPreferences prefs, final Resources res) { + return prefs.getBoolean(PREF_CENTER_SUGGESTION_TEXT_TO_COMMIT, res.getBoolean(R.bool.config_center_suggestion_text_to_commit)); + } + 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..a41784915 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 mCenterSuggestionTextToCommit; public final boolean mGestureInputEnabled; public final boolean mGestureTrailEnabled; public final boolean mGestureFloatingPreviewTextEnabled; @@ -161,6 +162,7 @@ public SettingsValues(final Context context, final SharedPreferences prefs, fina mAutoCorrectEnabled = mAutoCorrectionEnabledPerUserSettings && (mInputAttributes.mInputTypeShouldAutoCorrect || Settings.readMoreAutoCorrectEnabled(prefs)) && (mUrlDetectionEnabled || !InputTypeUtils.isUriOrEmailType(mInputAttributes.mInputType)); + mCenterSuggestionTextToCommit = Settings.readCenterSuggestionTextToCommit(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..f069ff21c 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 6103af717..5ae993b24 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -124,6 +124,10 @@ Aggressive Very aggressive + + Center text to commit + + If enabled, the middle suggestion will show the text to be committed 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 33fc9b3b5..74195bbfa 100644 --- a/app/src/main/res/xml/prefs_screen_correction.xml +++ b/app/src/main/res/xml/prefs_screen_correction.xml @@ -99,6 +99,13 @@ android:defaultValue="true" android:persistent="true" /> + +