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(); int action = textField.getAction();
boolean actionPerformed;
if (action == TextField.IME_ACTION_ENTER) { if (action == TextField.IME_ACTION_ENTER) {
boolean actionPerformed = appHacks.onEnter(); actionPerformed = appHacks.onEnter();
if (actionPerformed) { if (actionPerformed) {
forceShowWindow(); forceShowWindow();
} }
updateShiftState(true, false);
return actionPerformed; 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(); resetKeyRepeat();
mInputMode = determineInputMode(); mInputMode = determineInputMode();
determineTextCase(); determineTextCase();
updateShiftState(true, false);
suggestionOps.set(null); suggestionOps.set(null);
return true; return true;
@ -232,7 +233,7 @@ public abstract class TypingHandler extends KeyPadHandler {
autoCorrectSpace(text, true, -1); autoCorrectSpace(text, true, -1);
forceShowWindow(); forceShowWindow();
mainView.renderDynamicKeys(); updateShiftState(true, false);
return true; return true;
} }
@ -371,8 +372,6 @@ public abstract class TypingHandler extends KeyPadHandler {
protected void onAcceptSuggestionAutomatically(String word) { protected void onAcceptSuggestionAutomatically(String word) {
mInputMode.onAcceptSuggestion(word, true); mInputMode.onAcceptSuggestion(word, true);
autoCorrectSpace(word, false, mInputMode.getSequence().isEmpty() ? -1 : mInputMode.getSequence().charAt(0) - '0'); autoCorrectSpace(word, false, mInputMode.getSequence().isEmpty() ? -1 : mInputMode.getSequence().charAt(0) - '0');
mInputMode.determineNextWordTextCase(-1);
updateShiftState();
} }
private void onAcceptSuggestionsDelayed(String word) { private void onAcceptSuggestionsDelayed(String word) {
@ -384,6 +383,7 @@ public abstract class TypingHandler extends KeyPadHandler {
mInputMode.onAcceptSuggestion(word); mInputMode.onAcceptSuggestion(word);
if (!word.isEmpty()) { if (!word.isEmpty()) {
autoCorrectSpace(word, true, fromKey); autoCorrectSpace(word, true, fromKey);
updateShiftState(true, false);
resetKeyRepeat(); resetKeyRepeat();
} }
} }
@ -431,9 +431,7 @@ public abstract class TypingHandler extends KeyPadHandler {
String trimmedWord = suggestionOps.getCurrent(mLanguage, mInputMode.getSequenceLength()); String trimmedWord = suggestionOps.getCurrent(mLanguage, mInputMode.getSequenceLength());
appHacks.setComposingTextWithHighlightedStem(trimmedWord, mInputMode); appHacks.setComposingTextWithHighlightedStem(trimmedWord, mInputMode);
if (!suggestionOps.isEmpty() && new Text(suggestionOps.getCurrent()).isAlphabetic()) { updateShiftState(false, true);
updateShiftState();
}
forceShowWindow(); 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); setStatusIcon(mInputMode, mLanguage);
mainView.renderDynamicKeys(); mainView.renderDynamicKeys();
if (!mainView.isTextEditingPaletteShown() && !mainView.isCommandPaletteShown()) { if (!mainView.isTextEditingPaletteShown() && !mainView.isCommandPaletteShown()) {
statusBar.setText(mInputMode); statusBar.setText(mInputMode);
} }
} }
protected void updateShiftState() {
updateShiftState(false, false);
}
} }

View file

@ -51,15 +51,16 @@ public class AutoTextCase {
if ( if (
// When the setting is off, don't do any changes. // When the setting is off, don't do any changes.
!settings.getAutoTextCase() !settings.getAutoTextCase()
// If the user has explicitly selected a text case, we respect that. // If the user has explicitly selected uppercase, we respect that.
|| currentTextCase == InputMode.CASE_UPPER || currentTextCase == InputMode.CASE_LOWER || currentTextCase == InputMode.CASE_UPPER
// we do not have text fields that expect sentences, so disable the feature to save some resources // we do not have text fields that expect sentences, so disable the feature to save some resources
|| isUs || isUs
) { ) {
return currentTextCase; 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; return textFieldTextCase;
} }
@ -79,8 +80,9 @@ public class AutoTextCase {
return InputMode.CASE_CAPITALIZE; return InputMode.CASE_CAPITALIZE;
} }
// Prevent English "I", inserted in the middle of a word, from being uppercase. // 1. Stay in lowercase within the same sentence, in case the user has selected lowercase.
if (sequences.isEnglishI(language, digitSequence) && Text.isNextToWord(beforeCursor)) { // 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; return InputMode.CASE_LOWER;
} }