1
0
Fork 0

allowed Auto text case selector to override lowercase after a new line or after starting a new sentence

This commit is contained in:
sspanak 2025-06-16 14:49:51 +03:00 committed by Dimo Karaivanov
parent 0fb4dbfce4
commit 612ab66075
3 changed files with 34 additions and 14 deletions

View file

@ -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;
}

View file

@ -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);
}
}

View file

@ -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;
}