Skip to content

Commit fe833c4

Browse files
committed
Add option for no automatic spaces
1 parent dff21d6 commit fe833c4

File tree

4 files changed

+43
-11
lines changed

4 files changed

+43
-11
lines changed

java/res/values/strings-uix.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,9 +451,10 @@
451451

452452
<!-- Automatic space insertion -->
453453
<string name="typing_settings_auto_space_mode">Automatic spaces mode</string>
454-
<string name="typing_settings_auto_space_mode_auto">Automatically insert spaces after punctuation or after inserting suggestions</string>
455-
<string name="typing_settings_auto_space_mode_suggestions">Automatically insert spaces only after inserting suggestions</string>
456-
<string name="typing_settings_auto_space_mode_legacy">Do not automatically insert any spaces (legacy mode)</string>
454+
<string name="typing_settings_auto_space_mode_auto2">Immediate space after suggestions &amp; punctuation</string>
455+
<string name="typing_settings_auto_space_mode_suggestions2">Immediate space after suggestions</string>
456+
<string name="typing_settings_auto_space_mode_legacy2">Delayed space after suggestions (legacy mode)</string>
457+
<string name="typing_settings_auto_space_mode_none2">Disabled (not recommended)</string>
457458

458459
<!-- Misc keyboard settings -->
459460
<string name="keyboard_settings_title">Keyboard</string>

java/src/org/futo/inputmethod/latin/inputlogic/InputLogic.java

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,27 @@ public InputTransaction onTextInput(final SettingsValues settingsValues, final E
292292
return inputTransaction;
293293
}
294294

295+
/** Only used when automatic spaces is set to NONE */
296+
private void insertSuggestionAndKeepComposing(final SettingsValues settingsValues,
297+
final String word,
298+
final boolean updateSuggestions) {
299+
final boolean needToUpdateSuggestionStrip = updateSuggestions && word != mWordComposer.getTypedWord();
300+
301+
if(word.indexOf(' ') != -1 || mWordComposer.isBatchMode()) {
302+
commitChosenWord(settingsValues, word, LastComposedWord.COMMIT_TYPE_MANUAL_PICK,
303+
LastComposedWord.NOT_A_SEPARATOR, 1);
304+
mLastComposedWord.deactivate();
305+
resetComposingWord(settingsValues, false);
306+
} else {
307+
final int[] codePoints = StringUtils.toCodePointArray(word);
308+
mWordComposer.setComposingWord(codePoints,
309+
mImeHelper.getCodepointCoordinates(codePoints));
310+
setComposingTextInternal(word, 1);
311+
}
312+
313+
if(needToUpdateSuggestionStrip) postUpdateSuggestionStrip(SuggestedWords.INPUT_STYLE_TYPING);
314+
}
315+
295316
/**
296317
* A suggestion was picked from the suggestion strip.
297318
* @param settingsValues the current values of the settings.
@@ -365,6 +386,14 @@ public InputTransaction onPickSuggestionManually(final SettingsValues settingsVa
365386
return inputTransaction;
366387
}
367388

389+
// The logic for no auto-spaces is a little different, we need to stay in composing
390+
// state. If the suggestion has spaces in it, then we have to compose the final word.
391+
if(settingsValues.mAltSpacesMode == Settings.SPACES_MODE_NONE) {
392+
insertSuggestionAndKeepComposing(settingsValues, suggestion, true);
393+
mConnection.endBatchEdit();
394+
return inputTransaction;
395+
}
396+
368397
commitChosenWord(settingsValues, suggestion, LastComposedWord.COMMIT_TYPE_MANUAL_PICK,
369398
LastComposedWord.NOT_A_SEPARATOR, suggestionInfo.isKindOf(SuggestedWordInfo.KIND_TYPED) ? 3 : 1);
370399
mConnection.endBatchEdit();
@@ -621,7 +650,7 @@ public void onStartBatchInput(final SettingsValues settingsValues,
621650
|| settingsValues.isUsuallyFollowedBySpace(codePointBeforeCursor)) {
622651
final boolean autoShiftHasBeenOverriden = keyboardSwitcher.getKeyboardShiftMode() !=
623652
getCurrentAutoCapsState(settingsValues);
624-
mSpaceState = SpaceState.PHANTOM;
653+
if(settingsValues.mAltSpacesMode != Settings.SPACES_MODE_NONE) mSpaceState = SpaceState.PHANTOM;
625654
if (!autoShiftHasBeenOverriden) {
626655
// When we change the space state, we need to update the shift state of the
627656
// keyboard unless it has been overridden manually. This is happening for example
@@ -943,7 +972,7 @@ private void handleNonSeparatorEvent(final Event event, final SettingsValues set
943972
insertAutomaticSpaceIfOptionsAndTextAllow(settingsValues);
944973
}
945974

946-
if (mWordComposer.isCursorFrontOrMiddleOfComposingWord()) {
975+
if (mWordComposer.isCursorFrontOrMiddleOfComposingWord() || mWordComposer.isBatchMode()) {
947976
// If we are in the middle of a recorrection, we need to commit the recorrection
948977
// first so that we can insert the character at the current cursor position.
949978
// We also need to unlearn the original word that is now being corrected.
@@ -2036,7 +2065,7 @@ private void revertCommit(final InputTransaction inputTransaction,
20362065
if (inputTransaction.mSettingsValues.mSpacingAndPunctuations.mCurrentLanguageHasSpaces) {
20372066
mConnection.commitText(textToCommit, 1);
20382067
if (usePhantomSpace) {
2039-
mSpaceState = SpaceState.PHANTOM;
2068+
if(settingsValues.mAltSpacesMode != Settings.SPACES_MODE_NONE) mSpaceState = SpaceState.PHANTOM;
20402069
}
20412070
} else {
20422071
// For languages without spaces, we revert the typed string but the cursor is flush
@@ -2353,7 +2382,7 @@ private void insertOrSetPhantomSpace(final SettingsValues settingsValues) {
23532382

23542383
mSpaceState = SpaceState.ANTIPHANTOM;
23552384
sendKeyCodePoint(settingsValues, Constants.CODE_SPACE);
2356-
} else {
2385+
} else if(settingsValues.mAltSpacesMode != Settings.SPACES_MODE_NONE) {
23572386
mSpaceState = SpaceState.PHANTOM;
23582387
}
23592388
}
@@ -2378,7 +2407,7 @@ public void onUpdateTailBatchInputCompleted(final SettingsValues settingsValues,
23782407
setComposingTextInternal(batchInputText, 1);
23792408
mConnection.endBatchEdit();
23802409
// Space state must be updated before calling updateShiftState
2381-
mSpaceState = SpaceState.PHANTOM;
2410+
if(settingsValues.mAltSpacesMode != Settings.SPACES_MODE_NONE) mSpaceState = SpaceState.PHANTOM;
23822411
keyboardSwitcher.requestUpdatingShiftState(getCurrentAutoCapsState(settingsValues));
23832412

23842413
updateUiInputState();

java/src/org/futo/inputmethod/latin/settings/Settings.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
132132
public static final int BACKSPACE_MODE_WORDS = 1; // Long-press backspace and swipe backspace removes entire words
133133

134134
public static final String PREF_ALT_SPACES_MODE = "pref_alt_spaces";
135+
public static final int SPACES_MODE_NONE = -1; // No phantom spaces, no antiphantom
135136
public static final int SPACES_MODE_LEGACY = 0; // Only use phantom spaces
136137
public static final int SPACES_MODE_SUGGESTIONS = 1; // Use antiphantom for suggestion, none for punctuation
137138
public static final int SPACES_MODE_ALL = 2; // Use antiphantom for all

java/src/org/futo/inputmethod/latin/uix/settings/pages/Typing.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -619,9 +619,10 @@ val LongPressMenu = UserSettingsMenu(
619619
private fun AutoSpacesSetting() {
620620
val altSpacesMode = useSharedPrefsInt(Settings.PREF_ALT_SPACES_MODE, Settings.DEFAULT_ALT_SPACES_MODE)
621621
val autoSpaceModes = mapOf(
622-
Settings.SPACES_MODE_ALL to stringResource(R.string.typing_settings_auto_space_mode_auto),
623-
Settings.SPACES_MODE_SUGGESTIONS to stringResource(R.string.typing_settings_auto_space_mode_suggestions),
624-
Settings.SPACES_MODE_LEGACY to stringResource(R.string.typing_settings_auto_space_mode_legacy)
622+
Settings.SPACES_MODE_ALL to stringResource(R.string.typing_settings_auto_space_mode_auto2),
623+
Settings.SPACES_MODE_SUGGESTIONS to stringResource(R.string.typing_settings_auto_space_mode_suggestions2),
624+
Settings.SPACES_MODE_LEGACY to stringResource(R.string.typing_settings_auto_space_mode_legacy2),
625+
Settings.SPACES_MODE_NONE to stringResource(R.string.typing_settings_auto_space_mode_none2),
625626
)
626627
DropDownPickerSettingItem(
627628
label = stringResource(R.string.typing_settings_auto_space_mode),

0 commit comments

Comments
 (0)