mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-04-18 13:22:03 +00:00
make reverting autocorrect on backspace optional
fixes GH-210
This commit is contained in:
parent
c0b14635fd
commit
f5bc89b91d
7 changed files with 21 additions and 4 deletions
|
@ -1198,7 +1198,7 @@ public final class InputLogic {
|
|||
}
|
||||
inputTransaction.setRequiresUpdateSuggestions();
|
||||
} else {
|
||||
if (mLastComposedWord.canRevertCommit()) {
|
||||
if (mLastComposedWord.canRevertCommit() && inputTransaction.getMSettingsValues().mBackspaceRevertsAutocorrect) {
|
||||
final String lastComposedWord = mLastComposedWord.mTypedWord;
|
||||
revertCommit(inputTransaction);
|
||||
StatsUtils.onRevertAutoCorrect();
|
||||
|
|
|
@ -63,6 +63,7 @@ object Defaults {
|
|||
const val PREF_MORE_AUTO_CORRECTION = false
|
||||
const val PREF_AUTO_CORRECT_THRESHOLD = 0.185f
|
||||
const val PREF_AUTOCORRECT_SHORTCUTS = true
|
||||
const val PREF_BACKSPACE_REVERTS_AUTOCORRECT = true
|
||||
const val PREF_CENTER_SUGGESTION_TEXT_TO_ENTER = false
|
||||
const val PREF_SHOW_SUGGESTIONS = true
|
||||
const val PREF_ALWAYS_SHOW_SUGGESTIONS = false
|
||||
|
|
|
@ -71,6 +71,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
|
|||
public static final String PREF_MORE_AUTO_CORRECTION = "more_auto_correction";
|
||||
public static final String PREF_AUTO_CORRECT_THRESHOLD = "auto_correct_threshold";
|
||||
public static final String PREF_AUTOCORRECT_SHORTCUTS = "autocorrect_shortcuts";
|
||||
public static final String PREF_BACKSPACE_REVERTS_AUTOCORRECT = "backspace_reverts_autocorrect";
|
||||
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";
|
||||
|
|
|
@ -135,6 +135,7 @@ public class SettingsValues {
|
|||
public final boolean mAutoCorrectionEnabledPerUserSettings;
|
||||
public final boolean mAutoCorrectEnabled;
|
||||
public final float mAutoCorrectionThreshold;
|
||||
public final boolean mBackspaceRevertsAutocorrect;
|
||||
public final int mScoreLimitForAutocorrect;
|
||||
public final boolean mAutoCorrectShortcuts;
|
||||
private final boolean mSuggestionsEnabledPerUserSettings;
|
||||
|
@ -199,6 +200,7 @@ public class SettingsValues {
|
|||
mScoreLimitForAutocorrect = (mAutoCorrectionThreshold < 0) ? 600000 // very aggressive
|
||||
: (mAutoCorrectionThreshold < 0.07 ? 800000 : 950000); // aggressive or modest
|
||||
mAutoCorrectShortcuts = prefs.getBoolean(Settings.PREF_AUTOCORRECT_SHORTCUTS, Defaults.PREF_AUTOCORRECT_SHORTCUTS);
|
||||
mBackspaceRevertsAutocorrect = prefs.getBoolean(Settings.PREF_BACKSPACE_REVERTS_AUTOCORRECT, Defaults.PREF_BACKSPACE_REVERTS_AUTOCORRECT);
|
||||
mBigramPredictionEnabled = prefs.getBoolean(Settings.PREF_BIGRAM_PREDICTIONS, Defaults.PREF_BIGRAM_PREDICTIONS);
|
||||
mSuggestClipboardContent = prefs.getBoolean(Settings.PREF_SUGGEST_CLIPBOARD_CONTENT, Defaults.PREF_SUGGEST_CLIPBOARD_CONTENT);
|
||||
mDoubleSpacePeriodTimeout = 1100; // ms
|
||||
|
|
|
@ -59,6 +59,7 @@ fun TextCorrectionScreen(
|
|||
if (autocorrectEnabled) Settings.PREF_MORE_AUTO_CORRECTION else null,
|
||||
if (autocorrectEnabled) Settings.PREF_AUTOCORRECT_SHORTCUTS else null,
|
||||
if (autocorrectEnabled) Settings.PREF_AUTO_CORRECT_THRESHOLD else null,
|
||||
if (autocorrectEnabled) Settings.PREF_BACKSPACE_REVERTS_AUTOCORRECT else null,
|
||||
Settings.PREF_AUTO_CAP,
|
||||
R.string.settings_category_space,
|
||||
Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD,
|
||||
|
@ -123,6 +124,9 @@ fun createCorrectionSettings(context: Context) = listOf(
|
|||
// todo: consider making it a slider, and maybe somehow adjust range so we can show %
|
||||
ListPreference(it, items, Defaults.PREF_AUTO_CORRECT_THRESHOLD)
|
||||
},
|
||||
Setting(context, Settings.PREF_BACKSPACE_REVERTS_AUTOCORRECT, R.string.backspace_reverts_autocorrect) {
|
||||
SwitchPreference(it, Defaults.PREF_BACKSPACE_REVERTS_AUTOCORRECT)
|
||||
},
|
||||
Setting(context, Settings.PREF_AUTO_CAP,
|
||||
R.string.auto_cap, R.string.auto_cap_summary
|
||||
) {
|
||||
|
|
|
@ -128,6 +128,8 @@
|
|||
<string name="auto_correct_shortcuts">Auto-correct shortcuts</string>
|
||||
<!-- Description for auto_correct_shortcuts -->
|
||||
<string name="auto_correct_shortcuts_summary">When enabled shortcuts might be expanded by autocorrect</string>
|
||||
<!-- Option to undo auto correction with backspace -->
|
||||
<string name="backspace_reverts_autocorrect">Backspace reverts autocorrect</string>
|
||||
<!-- Option to disable auto correction. -->
|
||||
<string name="auto_correction_threshold_mode_off">Off</string>
|
||||
<!-- Option to suggest auto correction suggestions modestly. Auto-corrects only to a word which has small edit distance from typed word. -->
|
||||
|
|
|
@ -639,13 +639,20 @@ class InputLogicTest {
|
|||
|
||||
@Test fun `revert autocorrect on delete`() {
|
||||
reset()
|
||||
setInputType(InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_AUTO_CORRECT)
|
||||
chainInput("hullo")
|
||||
getAutocorrectedWithSpaceAfter("hello", "hullo")
|
||||
assertEquals("hello ", text)
|
||||
functionalKeyPress(KeyCode.DELETE)
|
||||
assertEquals("hullo", text)
|
||||
|
||||
// todo: now we want some way to disable revert on backspace, either per setting or something else
|
||||
// need to avoid getting into the mLastComposedWord.canRevertCommit() part of handleBackspaceEvent
|
||||
reset()
|
||||
setInputType(InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_AUTO_CORRECT)
|
||||
latinIME.prefs().edit { putBoolean(Settings.PREF_BACKSPACE_REVERTS_AUTOCORRECT, false) }
|
||||
chainInput("hullo")
|
||||
getAutocorrectedWithSpaceAfter("hello", "hullo")
|
||||
functionalKeyPress(KeyCode.DELETE)
|
||||
assertEquals("hello", text)
|
||||
}
|
||||
|
||||
@Test fun `remove glide typing word on delete`() {
|
||||
|
@ -803,7 +810,7 @@ class InputLogicTest {
|
|||
val info = SuggestedWordInfo(suggestion, "", 0, 0, null, 0, 0)
|
||||
val typedInfo = SuggestedWordInfo(typedWord, "", 0, 0, null, 0, 0)
|
||||
val sw = SuggestedWords(ArrayList(listOf(typedInfo, info)), null, typedInfo, false, true, false, 0, 0)
|
||||
latinIME.mInputLogic.setSuggestedWords(sw)
|
||||
latinIME.mInputLogic.setSuggestedWords(sw) // this prepares for autocorrect
|
||||
input(' ')
|
||||
checkConnectionConsistency()
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue