diff --git a/app/src/main/java/io/github/sspanak/tt9/ime/HotkeyHandler.java b/app/src/main/java/io/github/sspanak/tt9/ime/HotkeyHandler.java index 75b68860..0ca3fd6e 100644 --- a/app/src/main/java/io/github/sspanak/tt9/ime/HotkeyHandler.java +++ b/app/src/main/java/io/github/sspanak/tt9/ime/HotkeyHandler.java @@ -47,15 +47,22 @@ public abstract class HotkeyHandler extends CommandHandler { int action = textField.getAction(); + boolean actionPerformed; + if (action == TextField.IME_ACTION_ENTER) { - boolean actionPerformed = appHacks.onEnter(); + actionPerformed = appHacks.onEnter(); if (actionPerformed) { forceShowWindow(); } + + updateShiftState(true, false); return actionPerformed; } - return appHacks.onAction(action) || textField.performAction(action); + actionPerformed = appHacks.onAction(action) || textField.performAction(action); + updateShiftState(true, false); + + return actionPerformed; } diff --git a/app/src/main/java/io/github/sspanak/tt9/ime/TypingHandler.java b/app/src/main/java/io/github/sspanak/tt9/ime/TypingHandler.java index 0501b350..3d81f132 100644 --- a/app/src/main/java/io/github/sspanak/tt9/ime/TypingHandler.java +++ b/app/src/main/java/io/github/sspanak/tt9/ime/TypingHandler.java @@ -73,6 +73,7 @@ public abstract class TypingHandler extends KeyPadHandler { resetKeyRepeat(); mInputMode = determineInputMode(); determineTextCase(); + updateShiftState(true, false); suggestionOps.set(null); return true; @@ -232,7 +233,7 @@ public abstract class TypingHandler extends KeyPadHandler { autoCorrectSpace(text, true, -1); forceShowWindow(); - mainView.renderDynamicKeys(); + updateShiftState(true, false); return true; } @@ -371,8 +372,6 @@ public abstract class TypingHandler extends KeyPadHandler { protected void onAcceptSuggestionAutomatically(String word) { mInputMode.onAcceptSuggestion(word, true); autoCorrectSpace(word, false, mInputMode.getSequence().isEmpty() ? -1 : mInputMode.getSequence().charAt(0) - '0'); - mInputMode.determineNextWordTextCase(-1); - updateShiftState(); } private void onAcceptSuggestionsDelayed(String word) { @@ -384,6 +383,7 @@ public abstract class TypingHandler extends KeyPadHandler { mInputMode.onAcceptSuggestion(word); if (!word.isEmpty()) { autoCorrectSpace(word, true, fromKey); + updateShiftState(true, false); resetKeyRepeat(); } } @@ -431,9 +431,7 @@ public abstract class TypingHandler extends KeyPadHandler { String trimmedWord = suggestionOps.getCurrent(mLanguage, mInputMode.getSequenceLength()); appHacks.setComposingTextWithHighlightedStem(trimmedWord, mInputMode); - if (!suggestionOps.isEmpty() && new Text(suggestionOps.getCurrent()).isAlphabetic()) { - updateShiftState(); - } + updateShiftState(false, true); forceShowWindow(); } @@ -446,11 +444,24 @@ public abstract class TypingHandler extends KeyPadHandler { } - protected void updateShiftState() { + protected void updateShiftState(boolean determineTextCase, boolean onlyWhenWords) { + if (onlyWhenWords && (suggestionOps.isEmpty() || !new Text(suggestionOps.getCurrent()).isAlphabetic())) { + return; + } + + if (determineTextCase) { + mInputMode.determineNextWordTextCase(-1); + } + setStatusIcon(mInputMode, mLanguage); mainView.renderDynamicKeys(); if (!mainView.isTextEditingPaletteShown() && !mainView.isCommandPaletteShown()) { statusBar.setText(mInputMode); } } + + + protected void updateShiftState() { + updateShiftState(false, false); + } } diff --git a/app/src/main/java/io/github/sspanak/tt9/ime/modes/helpers/AutoTextCase.java b/app/src/main/java/io/github/sspanak/tt9/ime/modes/helpers/AutoTextCase.java index d7a6611b..14a1855e 100644 --- a/app/src/main/java/io/github/sspanak/tt9/ime/modes/helpers/AutoTextCase.java +++ b/app/src/main/java/io/github/sspanak/tt9/ime/modes/helpers/AutoTextCase.java @@ -51,15 +51,16 @@ public class AutoTextCase { if ( // When the setting is off, don't do any changes. !settings.getAutoTextCase() - // If the user has explicitly selected a text case, we respect that. - || currentTextCase == InputMode.CASE_UPPER || currentTextCase == InputMode.CASE_LOWER + // If the user has explicitly selected uppercase, we respect that. + || currentTextCase == InputMode.CASE_UPPER // we do not have text fields that expect sentences, so disable the feature to save some resources || isUs ) { return currentTextCase; } - if (textFieldTextCase != InputMode.CASE_UNDEFINED) { + // lowercase also takes priority but not as strict as uppercase + if (textFieldTextCase != InputMode.CASE_UNDEFINED && currentTextCase != InputMode.CASE_LOWER) { return textFieldTextCase; } @@ -79,8 +80,9 @@ public class AutoTextCase { return InputMode.CASE_CAPITALIZE; } - // Prevent English "I", inserted in the middle of a word, from being uppercase. - if (sequences.isEnglishI(language, digitSequence) && Text.isNextToWord(beforeCursor)) { + // 1. Stay in lowercase within the same sentence, in case the user has selected lowercase. + // or 2. Prevent English "I", inserted in the middle of a word, from being uppercase. + if (currentTextCase == InputMode.CASE_LOWER || (sequences.isEnglishI(language, digitSequence) && Text.isNextToWord(beforeCursor))) { return InputMode.CASE_LOWER; }