Add more settings for autospace

fixes GH-1348
fixes GH-876
This commit is contained in:
Helium314 2025-03-26 18:05:00 +01:00
parent 88a7f41038
commit 66a07eb8d2
7 changed files with 66 additions and 12 deletions

View file

@ -474,6 +474,10 @@ public final class WordComposer {
return mIsBatchMode; return mIsBatchMode;
} }
public void unsetBatchMode() {
mIsBatchMode = false;
}
public void setRejectedBatchModeSuggestion(final String rejectedSuggestion) { public void setRejectedBatchModeSuggestion(final String rejectedSuggestion) {
mRejectedBatchModeSuggestion = rejectedSuggestion; mRejectedBatchModeSuggestion = rejectedSuggestion;
} }

View file

@ -323,6 +323,7 @@ public final class InputLogic {
// Don't allow cancellation of manual pick // Don't allow cancellation of manual pick
mLastComposedWord.deactivate(); mLastComposedWord.deactivate();
// Space state must be updated before calling updateShiftState // Space state must be updated before calling updateShiftState
if (settingsValues.mAutospaceAfterSuggestion)
mSpaceState = SpaceState.PHANTOM; mSpaceState = SpaceState.PHANTOM;
inputTransaction.requireShiftUpdate(InputTransaction.SHIFT_UPDATE_NOW); inputTransaction.requireShiftUpdate(InputTransaction.SHIFT_UPDATE_NOW);
@ -546,6 +547,7 @@ public final class InputLogic {
|| settingsValues.isUsuallyFollowedBySpace(codePointBeforeCursor)) { || settingsValues.isUsuallyFollowedBySpace(codePointBeforeCursor)) {
final boolean autoShiftHasBeenOverriden = keyboardSwitcher.getKeyboardShiftMode() != final boolean autoShiftHasBeenOverriden = keyboardSwitcher.getKeyboardShiftMode() !=
getCurrentAutoCapsState(settingsValues); getCurrentAutoCapsState(settingsValues);
if (settingsValues.mAutospaceBeforeGestureTyping)
mSpaceState = SpaceState.PHANTOM; mSpaceState = SpaceState.PHANTOM;
if (!autoShiftHasBeenOverriden) { if (!autoShiftHasBeenOverriden) {
// When we change the space state, we need to update the shift state of the // When we change the space state, we need to update the shift state of the
@ -686,10 +688,7 @@ public final class InputLogic {
if (mSuggestedWords.isPrediction()) { if (mSuggestedWords.isPrediction()) {
inputTransaction.setRequiresUpdateSuggestions(); inputTransaction.setRequiresUpdateSuggestions();
} }
// undo phantom space if it's because after punctuation if (mSpaceState == SpaceState.PHANTOM && inputTransaction.getMSettingsValues().mShiftRemovesAutospace)
// users who want to start a sentence with a lowercase letter may not like it
if (mSpaceState == SpaceState.PHANTOM
&& inputTransaction.getMSettingsValues().isUsuallyFollowedBySpace(mConnection.getCodePointBeforeCursor()))
mSpaceState = SpaceState.NONE; mSpaceState = SpaceState.NONE;
break; break;
case KeyCode.SETTINGS: case KeyCode.SETTINGS:
@ -930,6 +929,7 @@ public final class InputLogic {
// handleNonSpecialCharacterEvent which has the same name as other handle* methods but is // handleNonSpecialCharacterEvent which has the same name as other handle* methods but is
// not the same. // not the same.
boolean isComposingWord = mWordComposer.isComposingWord(); boolean isComposingWord = mWordComposer.isComposingWord();
mWordComposer.unsetBatchMode(); // relevant in case we continue a batch word with normal typing
// if we continue directly after a sometimesWordConnector, restart suggestions for the whole word // if we continue directly after a sometimesWordConnector, restart suggestions for the whole word
// (only with URL detection and suggestions enabled) // (only with URL detection and suggestions enabled)
@ -1127,7 +1127,7 @@ public final class InputLogic {
// A double quote behaves like it's usually followed by space if we're inside // A double quote behaves like it's usually followed by space if we're inside
// a double quote. // a double quote.
if (wasComposingWord if (wasComposingWord
&& settingsValues.mAutospaceAfterPunctuationEnabled && settingsValues.mAutospaceAfterPunctuation
&& (settingsValues.isUsuallyFollowedBySpace(codePoint) || isInsideDoubleQuoteOrAfterDigit)) { && (settingsValues.isUsuallyFollowedBySpace(codePoint) || isInsideDoubleQuoteOrAfterDigit)) {
mSpaceState = SpaceState.PHANTOM; mSpaceState = SpaceState.PHANTOM;
} }
@ -2168,6 +2168,7 @@ public final class InputLogic {
&& !(mConnection.getCodePointBeforeCursor() == Constants.CODE_PERIOD && mConnection.wordBeforeCursorMayBeEmail()) && !(mConnection.getCodePointBeforeCursor() == Constants.CODE_PERIOD && mConnection.wordBeforeCursorMayBeEmail())
) { ) {
mConnection.commitCodePoint(Constants.CODE_SPACE); mConnection.commitCodePoint(Constants.CODE_SPACE);
// todo: why not remove phantom space state?
} }
} }
@ -2202,11 +2203,13 @@ public final class InputLogic {
mConnection.beginBatchEdit(); mConnection.beginBatchEdit();
if (SpaceState.PHANTOM == mSpaceState) { if (SpaceState.PHANTOM == mSpaceState) {
insertAutomaticSpaceIfOptionsAndTextAllow(settingsValues); insertAutomaticSpaceIfOptionsAndTextAllow(settingsValues);
mSpaceState = SpaceState.NONE;
} }
mWordComposer.setBatchInputWord(batchInputText); mWordComposer.setBatchInputWord(batchInputText);
setComposingTextInternal(batchInputText, 1); setComposingTextInternal(batchInputText, 1);
mConnection.endBatchEdit(); mConnection.endBatchEdit();
// Space state must be updated before calling updateShiftState // Space state must be updated before calling updateShiftState
if (settingsValues.mAutospaceAfterGestureTyping)
mSpaceState = SpaceState.PHANTOM; mSpaceState = SpaceState.PHANTOM;
keyboardSwitcher.requestUpdatingShiftState(getCurrentAutoCapsState(settingsValues), getCurrentRecapitalizeState()); keyboardSwitcher.requestUpdatingShiftState(getCurrentAutoCapsState(settingsValues), getCurrentRecapitalizeState());
} }

View file

@ -92,6 +92,10 @@ object Defaults {
const val PREF_SPACE_VERTICAL_SWIPE = "none" const val PREF_SPACE_VERTICAL_SWIPE = "none"
const val PREF_DELETE_SWIPE = true const val PREF_DELETE_SWIPE = true
const val PREF_AUTOSPACE_AFTER_PUNCTUATION = false const val PREF_AUTOSPACE_AFTER_PUNCTUATION = false
const val PREF_AUTOSPACE_AFTER_SUGGESTION = true
const val PREF_AUTOSPACE_AFTER_GESTURE_TYPING = true
const val PREF_AUTOSPACE_BEFORE_GESTURE_TYPING = true
const val PREF_SHIFT_REMOVES_AUTOSPACE = false
const val PREF_ALWAYS_INCOGNITO_MODE = false const val PREF_ALWAYS_INCOGNITO_MODE = false
const val PREF_BIGRAM_PREDICTIONS = true const val PREF_BIGRAM_PREDICTIONS = true
const val PREF_SUGGEST_CLIPBOARD_CONTENT = true const val PREF_SUGGEST_CLIPBOARD_CONTENT = true

View file

@ -98,6 +98,10 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public static final String PREF_SPACE_VERTICAL_SWIPE = "vertical_space_swipe"; public static final String PREF_SPACE_VERTICAL_SWIPE = "vertical_space_swipe";
public static final String PREF_DELETE_SWIPE = "delete_swipe"; public static final String PREF_DELETE_SWIPE = "delete_swipe";
public static final String PREF_AUTOSPACE_AFTER_PUNCTUATION = "autospace_after_punctuation"; public static final String PREF_AUTOSPACE_AFTER_PUNCTUATION = "autospace_after_punctuation";
public static final String PREF_AUTOSPACE_AFTER_SUGGESTION = "autospace_after_suggestion";
public static final String PREF_AUTOSPACE_AFTER_GESTURE_TYPING = "autospace_after_gesture_typing";
public static final String PREF_AUTOSPACE_BEFORE_GESTURE_TYPING = "autospace_before_gesture_typing";
public static final String PREF_SHIFT_REMOVES_AUTOSPACE = "shift_removes_autospace";
public static final String PREF_ALWAYS_INCOGNITO_MODE = "always_incognito_mode"; public static final String PREF_ALWAYS_INCOGNITO_MODE = "always_incognito_mode";
public static final String PREF_BIGRAM_PREDICTIONS = "next_word_prediction"; public static final String PREF_BIGRAM_PREDICTIONS = "next_word_prediction";
public static final String PREF_SUGGEST_CLIPBOARD_CONTENT = "suggest_clipboard_content"; public static final String PREF_SUGGEST_CLIPBOARD_CONTENT = "suggest_clipboard_content";

View file

@ -77,7 +77,11 @@ public class SettingsValues {
public final int mSpaceSwipeVertical; public final int mSpaceSwipeVertical;
public final int mLanguageSwipeDistance; public final int mLanguageSwipeDistance;
public final boolean mDeleteSwipeEnabled; public final boolean mDeleteSwipeEnabled;
public final boolean mAutospaceAfterPunctuationEnabled; public final boolean mAutospaceAfterPunctuation;
public final boolean mAutospaceAfterSuggestion;
public final boolean mAutospaceAfterGestureTyping;
public final boolean mAutospaceBeforeGestureTyping;
public final boolean mShiftRemovesAutospace;
public final boolean mClipboardHistoryEnabled; public final boolean mClipboardHistoryEnabled;
public final long mClipboardHistoryRetentionTime; public final long mClipboardHistoryRetentionTime;
public final boolean mOneHandedModeEnabled; public final boolean mOneHandedModeEnabled;
@ -236,7 +240,11 @@ public class SettingsValues {
mSpaceSwipeVertical = Settings.readVerticalSpaceSwipe(prefs); mSpaceSwipeVertical = Settings.readVerticalSpaceSwipe(prefs);
mLanguageSwipeDistance = prefs.getInt(Settings.PREF_LANGUAGE_SWIPE_DISTANCE, Defaults.PREF_LANGUAGE_SWIPE_DISTANCE); mLanguageSwipeDistance = prefs.getInt(Settings.PREF_LANGUAGE_SWIPE_DISTANCE, Defaults.PREF_LANGUAGE_SWIPE_DISTANCE);
mDeleteSwipeEnabled = prefs.getBoolean(Settings.PREF_DELETE_SWIPE, Defaults.PREF_DELETE_SWIPE); mDeleteSwipeEnabled = prefs.getBoolean(Settings.PREF_DELETE_SWIPE, Defaults.PREF_DELETE_SWIPE);
mAutospaceAfterPunctuationEnabled = prefs.getBoolean(Settings.PREF_AUTOSPACE_AFTER_PUNCTUATION, Defaults.PREF_AUTOSPACE_AFTER_PUNCTUATION); mAutospaceAfterPunctuation = prefs.getBoolean(Settings.PREF_AUTOSPACE_AFTER_PUNCTUATION, Defaults.PREF_AUTOSPACE_AFTER_PUNCTUATION);
mAutospaceAfterSuggestion = prefs.getBoolean(Settings.PREF_AUTOSPACE_AFTER_SUGGESTION, Defaults.PREF_AUTOSPACE_AFTER_SUGGESTION);
mAutospaceAfterGestureTyping = prefs.getBoolean(Settings.PREF_AUTOSPACE_AFTER_GESTURE_TYPING, Defaults.PREF_AUTOSPACE_AFTER_GESTURE_TYPING);
mAutospaceBeforeGestureTyping = prefs.getBoolean(Settings.PREF_AUTOSPACE_BEFORE_GESTURE_TYPING, Defaults.PREF_AUTOSPACE_BEFORE_GESTURE_TYPING);
mShiftRemovesAutospace = prefs.getBoolean(Settings.PREF_SHIFT_REMOVES_AUTOSPACE, Defaults.PREF_SHIFT_REMOVES_AUTOSPACE);
mClipboardHistoryEnabled = prefs.getBoolean(Settings.PREF_ENABLE_CLIPBOARD_HISTORY, Defaults.PREF_ENABLE_CLIPBOARD_HISTORY); mClipboardHistoryEnabled = prefs.getBoolean(Settings.PREF_ENABLE_CLIPBOARD_HISTORY, Defaults.PREF_ENABLE_CLIPBOARD_HISTORY);
mClipboardHistoryRetentionTime = prefs.getInt(Settings.PREF_CLIPBOARD_HISTORY_RETENTION_TIME, Defaults.PREF_CLIPBOARD_HISTORY_RETENTION_TIME); mClipboardHistoryRetentionTime = prefs.getInt(Settings.PREF_CLIPBOARD_HISTORY_RETENTION_TIME, Defaults.PREF_CLIPBOARD_HISTORY_RETENTION_TIME);

View file

@ -22,6 +22,7 @@ import helium314.keyboard.latin.R
import helium314.keyboard.latin.permissions.PermissionsUtil import helium314.keyboard.latin.permissions.PermissionsUtil
import helium314.keyboard.latin.settings.Defaults import helium314.keyboard.latin.settings.Defaults
import helium314.keyboard.latin.settings.Settings import helium314.keyboard.latin.settings.Settings
import helium314.keyboard.latin.utils.JniUtils
import helium314.keyboard.latin.utils.Log import helium314.keyboard.latin.utils.Log
import helium314.keyboard.latin.utils.getActivity import helium314.keyboard.latin.utils.getActivity
import helium314.keyboard.latin.utils.prefs import helium314.keyboard.latin.utils.prefs
@ -49,6 +50,7 @@ fun TextCorrectionScreen(
Log.v("irrelevant", "stupid way to trigger recomposition on preference change") Log.v("irrelevant", "stupid way to trigger recomposition on preference change")
val autocorrectEnabled = prefs.getBoolean(Settings.PREF_AUTO_CORRECTION, Defaults.PREF_AUTO_CORRECTION) val autocorrectEnabled = prefs.getBoolean(Settings.PREF_AUTO_CORRECTION, Defaults.PREF_AUTO_CORRECTION)
val suggestionsEnabled = prefs.getBoolean(Settings.PREF_SHOW_SUGGESTIONS, Defaults.PREF_SHOW_SUGGESTIONS) val suggestionsEnabled = prefs.getBoolean(Settings.PREF_SHOW_SUGGESTIONS, Defaults.PREF_SHOW_SUGGESTIONS)
val gestureEnabled = JniUtils.sHaveGestureLib && prefs.getBoolean(Settings.PREF_GESTURE_INPUT, Defaults.PREF_GESTURE_INPUT)
val items = listOf( val items = listOf(
SettingsWithoutKey.EDIT_PERSONAL_DICTIONARY, SettingsWithoutKey.EDIT_PERSONAL_DICTIONARY,
R.string.settings_category_correction, R.string.settings_category_correction,
@ -58,8 +60,13 @@ fun TextCorrectionScreen(
if (autocorrectEnabled) Settings.PREF_AUTOCORRECT_SHORTCUTS else null, if (autocorrectEnabled) Settings.PREF_AUTOCORRECT_SHORTCUTS else null,
if (autocorrectEnabled) Settings.PREF_AUTO_CORRECT_THRESHOLD else null, if (autocorrectEnabled) Settings.PREF_AUTO_CORRECT_THRESHOLD else null,
Settings.PREF_AUTO_CAP, Settings.PREF_AUTO_CAP,
R.string.settings_category_space,
Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD,
Settings.PREF_AUTOSPACE_AFTER_PUNCTUATION, Settings.PREF_AUTOSPACE_AFTER_PUNCTUATION,
Settings.PREF_AUTOSPACE_AFTER_SUGGESTION,
if (gestureEnabled) Settings.PREF_AUTOSPACE_BEFORE_GESTURE_TYPING else null,
if (gestureEnabled) Settings.PREF_AUTOSPACE_AFTER_GESTURE_TYPING else null,
Settings.PREF_SHIFT_REMOVES_AUTOSPACE,
R.string.settings_category_suggestions, R.string.settings_category_suggestions,
Settings.PREF_SHOW_SUGGESTIONS, Settings.PREF_SHOW_SUGGESTIONS,
if (suggestionsEnabled) Settings.PREF_ALWAYS_SHOW_SUGGESTIONS else null, if (suggestionsEnabled) Settings.PREF_ALWAYS_SHOW_SUGGESTIONS else null,
@ -131,6 +138,18 @@ fun createCorrectionSettings(context: Context) = listOf(
) { ) {
SwitchPreference(it, Defaults.PREF_AUTOSPACE_AFTER_PUNCTUATION) SwitchPreference(it, Defaults.PREF_AUTOSPACE_AFTER_PUNCTUATION)
}, },
Setting(context, Settings.PREF_AUTOSPACE_AFTER_SUGGESTION, R.string.autospace_after_suggestion) {
SwitchPreference(it, Defaults.PREF_AUTOSPACE_AFTER_SUGGESTION)
},
Setting(context, Settings.PREF_AUTOSPACE_AFTER_GESTURE_TYPING, R.string.autospace_after_gesture_typing) {
SwitchPreference(it, Defaults.PREF_AUTOSPACE_AFTER_GESTURE_TYPING)
},
Setting(context, Settings.PREF_AUTOSPACE_BEFORE_GESTURE_TYPING, R.string.autospace_before_gesture_typing) {
SwitchPreference(it, Defaults.PREF_AUTOSPACE_BEFORE_GESTURE_TYPING)
},
Setting(context, Settings.PREF_SHIFT_REMOVES_AUTOSPACE, R.string.shift_removes_autospace, R.string.shift_removes_autospace_summary) {
SwitchPreference(it, Defaults.PREF_SHIFT_REMOVES_AUTOSPACE)
},
Setting(context, Settings.PREF_SHOW_SUGGESTIONS, Setting(context, Settings.PREF_SHOW_SUGGESTIONS,
R.string.prefs_show_suggestions, R.string.prefs_show_suggestions_summary R.string.prefs_show_suggestions, R.string.prefs_show_suggestions_summary
) { ) {

View file

@ -38,6 +38,8 @@
<string name="settings_category_clipboard_history">Clipboard history</string> <string name="settings_category_clipboard_history">Clipboard history</string>
<!-- Settings category title for Text correction/Corrections --> <!-- Settings category title for Text correction/Corrections -->
<string name="settings_category_correction">Corrections</string> <string name="settings_category_correction">Corrections</string>
<!-- Settings category title for Text correction/Space -->
<string name="settings_category_space">Space</string>
<!-- Settings category title for Text correction/Suggestions --> <!-- Settings category title for Text correction/Suggestions -->
<string name="settings_category_suggestions">Suggestions</string> <string name="settings_category_suggestions">Suggestions</string>
<!-- Settings category title for Advanced/Experimental --> <!-- Settings category title for Advanced/Experimental -->
@ -209,10 +211,20 @@
<string name="load_gesture_library_button_load">Load library</string> <string name="load_gesture_library_button_load">Load library</string>
<!-- Button text for deleting gesture library --> <!-- Button text for deleting gesture library -->
<string name="load_gesture_library_button_delete">Delete library</string> <string name="load_gesture_library_button_delete">Delete library</string>
<!-- Preferences item for enabling inserting more spaces key --> <!-- Preferences item for inserting space after punctuation -->
<string name="autospace_after_punctuation">Autospace after punctuation</string> <string name="autospace_after_punctuation">Autospace after punctuation</string>
<!-- Description for "insert_more_spaces" option. --> <!-- Description for "autospace_after_punctuation" setting -->
<string name="autospace_after_punctuation_summary">Automatically insert space after punctuation when typing a new word</string> <string name="autospace_after_punctuation_summary">Automatically insert space after punctuation when typing a new word</string>
<!-- Preferences item for inserting space after manualle picking a suggestion -->
<string name="autospace_after_suggestion">Autospace after picking a suggestion</string>
<!-- Preferences item for inserting space before entering a word using gesture typing -->
<string name="autospace_before_gesture_typing">Autospace before gesture typing a word</string>
<!-- Preferences item for inserting space after entering a word using gesture typing -->
<string name="autospace_after_gesture_typing">Autospace after gesture typing a word</string>
<!-- Preferences item for avoiding automatic space insertion by pressing shift -->
<string name="shift_removes_autospace">No autospace when pressing shift</string>
<!-- Description for "autospace_after_punctuation" setting -->
<string name="shift_removes_autospace_summary">Shift removes pending autospace</string>
<!-- Preferences item for showing popup keys in long-press popup --> <!-- Preferences item for showing popup keys in long-press popup -->
<string name="show_popup_keys_title">Show more letters with diacritics in popup</string> <string name="show_popup_keys_title">Show more letters with diacritics in popup</string>
<!-- Option for showing only letters defined in the current language file in long-press popup --> <!-- Option for showing only letters defined in the current language file in long-press popup -->