Option to always show word to be enterd as middle suggestion (#739)

Co-authored-by: codokie <@>
Co-authored-by: Volterxien <volerxien.github@jacbo.me>
This commit is contained in:
Volterxien 2024-05-01 00:33:57 -04:00 committed by GitHub
parent 26a5934e2f
commit e0c5da380e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 28 additions and 4 deletions

View file

@ -115,13 +115,16 @@ class Suggest(private val mDictionaryFacilitator: DictionaryFacilitator) {
inputStyleIfNotPrediction inputStyleIfNotPrediction
} }
if (hasAutoCorrection) { // If there is an incoming autocorrection, make sure typed word is shown, so user is able to override it.
// make sure typed word is shown, so user is able to override incoming autocorrection // 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 (typedWordFirstOccurrenceWordInfo != null) {
if (SuggestionStripView.DEBUG_SUGGESTIONS) addDebugInfo(typedWordFirstOccurrenceWordInfo, typedWordString) if (SuggestionStripView.DEBUG_SUGGESTIONS) addDebugInfo(typedWordFirstOccurrenceWordInfo, typedWordString)
suggestionsList.add(2, typedWordFirstOccurrenceWordInfo) suggestionsList.add(indexOfTypedWord, typedWordFirstOccurrenceWordInfo)
} else { } else {
suggestionsList.add(2, suggestionsList.add(indexOfTypedWord,
SuggestedWordInfo(typedWordString, "", 0, SuggestedWordInfo.KIND_TYPED, SuggestedWordInfo(typedWordString, "", 0, SuggestedWordInfo.KIND_TYPED,
Dictionary.DICTIONARY_USER_TYPED, SuggestedWordInfo.NOT_AN_INDEX, SuggestedWordInfo.NOT_A_CONFIDENCE) Dictionary.DICTIONARY_USER_TYPED, SuggestedWordInfo.NOT_AN_INDEX, SuggestedWordInfo.NOT_A_CONFIDENCE)
) )

View file

@ -76,6 +76,7 @@ public final class CorrectionSettingsFragment extends SubScreenFragment
setPreferenceVisible(Settings.PREF_MORE_AUTO_CORRECTION, Settings.readAutoCorrectEnabled(getSharedPreferences())); 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_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_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(); turnOffLookupContactsIfNoPermission();
} }

View file

@ -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_AUTO_CORRECTION = "auto_correction";
public static final String PREF_MORE_AUTO_CORRECTION = "more_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_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_SHOW_SUGGESTIONS = "show_suggestions";
public static final String PREF_ALWAYS_SHOW_SUGGESTIONS = "always_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"; 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)); 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) { public static boolean readBlockPotentiallyOffensive(final SharedPreferences prefs, final Resources res) {
return prefs.getBoolean(PREF_BLOCK_POTENTIALLY_OFFENSIVE, return prefs.getBoolean(PREF_BLOCK_POTENTIALLY_OFFENSIVE,
res.getBoolean(R.bool.config_block_potentially_offensive)); res.getBoolean(R.bool.config_block_potentially_offensive));

View file

@ -87,6 +87,7 @@ public class SettingsValues {
public final List<String> mPopupKeyLabelSources; public final List<String> mPopupKeyLabelSources;
public final List<Locale> mSecondaryLocales; public final List<Locale> mSecondaryLocales;
public final boolean mBigramPredictionEnabled;// Use bigrams to predict the next word when there is no input for it yet 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 mGestureInputEnabled;
public final boolean mGestureTrailEnabled; public final boolean mGestureTrailEnabled;
public final boolean mGestureFloatingPreviewTextEnabled; public final boolean mGestureFloatingPreviewTextEnabled;
@ -161,6 +162,7 @@ public class SettingsValues {
mAutoCorrectEnabled = mAutoCorrectionEnabledPerUserSettings mAutoCorrectEnabled = mAutoCorrectionEnabledPerUserSettings
&& (mInputAttributes.mInputTypeShouldAutoCorrect || Settings.readMoreAutoCorrectEnabled(prefs)) && (mInputAttributes.mInputTypeShouldAutoCorrect || Settings.readMoreAutoCorrectEnabled(prefs))
&& (mUrlDetectionEnabled || !InputTypeUtils.isUriOrEmailType(mInputAttributes.mInputType)); && (mUrlDetectionEnabled || !InputTypeUtils.isUriOrEmailType(mInputAttributes.mInputType));
mCenterSuggestionTextToEnter = Settings.readCenterSuggestionTextToEnter(prefs, res);
mAutoCorrectionThreshold = mAutoCorrectEnabled mAutoCorrectionThreshold = mAutoCorrectEnabled
? readAutoCorrectionThreshold(res, prefs) ? readAutoCorrectionThreshold(res, prefs)
: AUTO_CORRECTION_DISABLED_THRESHOLD; : AUTO_CORRECTION_DISABLED_THRESHOLD;

View file

@ -6,6 +6,8 @@
--> -->
<resources> <resources>
<!-- By default, the centered suggestion will not show the word that should be entered -->
<bool name="config_center_suggestion_text_to_enter">false</bool>
<bool name="config_block_potentially_offensive">true</bool> <bool name="config_block_potentially_offensive">true</bool>
<!-- Default value for next word prediction: after entering a word and a space only, should we <!-- Default value for next word prediction: after entering a word and a space only, should we
look at input history to suggest a hopefully helpful suggestions for the next word? --> look at input history to suggest a hopefully helpful suggestions for the next word? -->

View file

@ -124,6 +124,10 @@
<string name="auto_correction_threshold_mode_aggressive">Aggressive</string> <string name="auto_correction_threshold_mode_aggressive">Aggressive</string>
<!-- Option to suggest auto correction suggestions very aggressively. Auto-corrects to a word which has even large edit distance from typed word. [CHAR LIMIT=20] --> <!-- Option to suggest auto correction suggestions very aggressively. Auto-corrects to a word which has even large edit distance from typed word. [CHAR LIMIT=20] -->
<string name="auto_correction_threshold_mode_very_aggressive">Very aggressive</string> <string name="auto_correction_threshold_mode_very_aggressive">Very aggressive</string>
<!-- Option to show the text to be entered as the middle middle suggestion -->
<string name="center_suggestion_text_to_enter">Always use middle suggestion</string>
<!-- Description for the center text to enter setting -->
<string name="center_suggestion_text_to_enter_summary">On pressing space or punctuation, the middle suggestion will be entered</string>
<!-- Option to enable using next word suggestions. After the user types a space, with this option on, the keyboard will try to predict the next word. --> <!-- Option to enable using next word suggestions. After the user types a space, with this option on, the keyboard will try to predict the next word. -->
<string name="bigram_prediction">Next-word suggestions</string> <string name="bigram_prediction">Next-word suggestions</string>
<!-- Description for "next word suggestion" option. This displays suggestions even when there is no input, based on the previous word. --> <!-- Description for "next word suggestion" option. This displays suggestions even when there is no input, based on the previous word. -->

View file

@ -101,6 +101,13 @@
android:defaultValue="true" android:defaultValue="true"
android:persistent="true" /> android:persistent="true" />
<SwitchPreference
android:key="center_suggestion_text_to_enter"
android:title="@string/center_suggestion_text_to_enter"
android:summary="@string/center_suggestion_text_to_enter_summary"
android:defaultValue="@bool/config_center_suggestion_text_to_enter"
android:persistent="true" />
<SwitchPreference <SwitchPreference
android:key="use_contacts" android:key="use_contacts"
android:title="@string/use_contacts_dict" android:title="@string/use_contacts_dict"