Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ object Defaults {
const val PREF_BACKSPACE_REVERTS_AUTOCORRECT = true
const val PREF_CENTER_SUGGESTION_TEXT_TO_ENTER = false
const val PREF_CENTER_TYPED_WORD = false
const val PREF_AUTOCORRECTION_RIGHT_OF_TYPED_WORD = false
const val PREF_SHOW_SUGGESTIONS = true
const val PREF_ALWAYS_SHOW_SUGGESTIONS = false
const val PREF_ALWAYS_SHOW_SUGGESTIONS_EXCEPT_WEB_TEXT = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ class Settings private constructor() : SharedPreferences.OnSharedPreferenceChang
const val PREF_BACKSPACE_REVERTS_AUTOCORRECT = "backspace_reverts_autocorrect"
const val PREF_CENTER_SUGGESTION_TEXT_TO_ENTER = "center_suggestion_text_to_enter"
const val PREF_CENTER_TYPED_WORD = "center_typed_word"
const val PREF_AUTOCORRECTION_RIGHT_OF_TYPED_WORD = "autocorrection_right_of_typed_word"
const val PREF_SHOW_SUGGESTIONS = "show_suggestions"
const val PREF_ALWAYS_SHOW_SUGGESTIONS = "always_show_suggestions"
const val PREF_ALWAYS_SHOW_SUGGESTIONS_EXCEPT_WEB_TEXT = "always_show_suggestions_except_web_text"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ open class SettingsValues(
val mSuggestPunctuation: Boolean
val mCenterSuggestionTextToEnter: Boolean
val mCenterTypedWord: Boolean
val mAutoCorrectionRightOfTypedWord: Boolean
val mGestureMethod: String
val mFullKeyboardSwipe: Int
val mGestureInputEnabled: Boolean
Expand Down Expand Up @@ -349,6 +350,7 @@ open class SettingsValues(
mAutoCorrectEnabled = mAutoCorrectionEnabledPerUserSettings && shouldAutoCorrectForField
mCenterSuggestionTextToEnter = prefs.getBoolean(Settings.PREF_CENTER_SUGGESTION_TEXT_TO_ENTER, Defaults.PREF_CENTER_SUGGESTION_TEXT_TO_ENTER)
mCenterTypedWord = prefs.getBoolean(Settings.PREF_CENTER_TYPED_WORD, Defaults.PREF_CENTER_TYPED_WORD)
mAutoCorrectionRightOfTypedWord = prefs.getBoolean(Settings.PREF_AUTOCORRECTION_RIGHT_OF_TYPED_WORD, Defaults.PREF_AUTOCORRECTION_RIGHT_OF_TYPED_WORD)
mAutoCorrectionThreshold = if (mAutoCorrectEnabled) prefs.getFloat(Settings.PREF_AUTO_CORRECT_THRESHOLD, Defaults.PREF_AUTO_CORRECT_THRESHOLD) else Float.MAX_VALUE
mScoreLimitForAutocorrect = if (mAutoCorrectionThreshold < 0) 600000 else (if (mAutoCorrectionThreshold < 0.07f) 800000 else 950000)
mAutoCorrectShortcuts = prefs.getBoolean(Settings.PREF_AUTOCORRECT_SHORTCUTS, Defaults.PREF_AUTOCORRECT_SHORTCUTS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ internal class SuggestionStripLayoutHelper(
)
return getPositionInSuggestionStrip(
indexInSuggestedWords, suggestedWords.mWillAutoCorrect,
shouldOmitTypedWord, mCenterPositionInStrip, mTypedWordPositionWhenAutocorrect, mCenterTypedWord
shouldOmitTypedWord, mCenterPositionInStrip, mTypedWordPositionWhenAutocorrect, mCenterTypedWord,
mCenterTypedWord && settingsValues.mAutoCorrectionRightOfTypedWord
&& mSuggestionsCountInStrip > mCenterPositionInStrip + 1 // there must be a position on the right
)
}

Expand Down Expand Up @@ -543,7 +545,7 @@ internal class SuggestionStripLayoutHelper(
indexInSuggestedWords: Int,
willAutoCorrect: Boolean, omitTypedWord: Boolean,
centerPositionInStrip: Int, typedWordPositionWhenAutoCorrect: Int,
centerTypedWord: Boolean = false
centerTypedWord: Boolean = false, autoCorrectionRight: Boolean = false
): Int {
if (omitTypedWord) {
if (indexInSuggestedWords == SuggestedWords.INDEX_OF_TYPED_WORD) {
Expand All @@ -555,6 +557,10 @@ internal class SuggestionStripLayoutHelper(
return centerPositionInStrip
}
if (indexInSuggestedWords == SuggestedWords.INDEX_OF_AUTO_CORRECTION) {
return if (autoCorrectionRight) centerPositionInStrip + 1 else typedWordPositionWhenAutoCorrect
}
// the suggestion that is usually right of the center goes to the left instead
if (autoCorrectionRight && indexInSuggestedWords == INDEX_OF_TYPED_WORD_WHEN_AUTOCORRECT + 1) {
return typedWordPositionWhenAutoCorrect
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ fun SuggestionsScreen(
if (suggestionsEnabled) Settings.PREF_SUGGESTIONS_COUNT_IN_STRIP else null,
if (suggestionsEnabled) Settings.PREF_CENTER_SUGGESTION_TEXT_TO_ENTER else null,
if (suggestionsEnabled) Settings.PREF_CENTER_TYPED_WORD else null,
if (suggestionsEnabled) Settings.PREF_AUTOCORRECTION_RIGHT_OF_TYPED_WORD else null,
Settings.PREF_SUGGEST_PUNCTUATION,

// Prediction & learning
Expand Down Expand Up @@ -256,6 +257,13 @@ fun createSuggestionsSettings(context: Context) = listOf(
) {
SwitchPreference(it, Defaults.PREF_CENTER_TYPED_WORD)
},
Setting(context, Settings.PREF_AUTOCORRECTION_RIGHT_OF_TYPED_WORD,
R.string.autocorrection_right_of_typed_word, R.string.autocorrection_right_of_typed_word_summary
) {
val prefs = LocalContext.current.prefs()
SwitchPreference(it, Defaults.PREF_AUTOCORRECTION_RIGHT_OF_TYPED_WORD,
enabled = prefs.getBoolean(Settings.PREF_CENTER_TYPED_WORD, Defaults.PREF_CENTER_TYPED_WORD))
},
Setting(context, Settings.PREF_SUGGEST_CLIPBOARD_CONTENT,
R.string.suggest_clipboard_content, R.string.suggest_clipboard_content_summary
) {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1734,4 +1734,6 @@ Ermöglicht lokale GGUF / llama.cpp-Inferenz für Korrekturlesen und Umschreiben
<string name="backup_api_keys_warning_confirm">API-Schlüssel einschließen</string>
<string name="gif_get_api_key">Holen Sie sich den API-Schlüssel</string>
<string name="gif_provider_disabled">Deaktiviert</string>
<string name="autocorrection_right_of_typed_word">Autokorrektur rechts vom getippten Wort</string>
<string name="autocorrection_right_of_typed_word_summary">Wenn das getippte Wort in der Mitte steht, erscheint die Autokorrektur rechts daneben statt links</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2418,4 +2418,6 @@ New dictionary:
<string name="gif_no_recent_items">No recent items</string>
<string name="gif_manage_local_media">Manage Local Media</string>
<string name="gif_get_api_key">Get API key</string>
<string name="autocorrection_right_of_typed_word">Auto-correction right of the typed word</string>
<string name="autocorrection_right_of_typed_word_summary">When the typed word is in the middle, show the auto-correction on its right instead of its left</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ class SuggestionStripLayoutHelperTest {
}
}

@Test fun autoCorrectionCanBeRightOfTypedWord() {
fun right(index: Int, center: Int = 1, left: Int = 0) =
getPositionInSuggestionStrip(index, true, true, center, left, centerTypedWord = true, autoCorrectionRight = true)
assertEquals(listOf(2, 1, 0), (1..3).map { right(it) })
assertEquals(listOf(3, 2, 1, 0, 4), (1..5).map { right(it, center = 2, left = 1) })
}

@Test fun typedWordIsInCenterWithFiveSuggestions() {
val positions = (1..5).map { position(it, willAutoCorrect = true, centerTypedWord = true, center = 2, left = 1) }
assertEquals(listOf(1, 2, 3, 0, 4), positions)
Expand Down