1
0
Fork 0

fixed not possible to change the text case of words like: 's, 're, 'll; and incorrect text case cycle order for regular words, when in the middle of a sentence

This commit is contained in:
sspanak 2025-06-23 12:54:43 +03:00 committed by Dimo Karaivanov
parent 548041be28
commit 1aa68eca60
5 changed files with 37 additions and 28 deletions

View file

@ -209,36 +209,27 @@ abstract public class CommandHandler extends TextEditingHandler {
protected boolean nextTextCase() {
if (!mInputMode.nextTextCase()) {
final String currentWord = suggestionOps.isEmpty() || mInputMode.getSequence().isEmpty() ? "" : suggestionOps.getCurrent();
if (!mInputMode.nextTextCase(currentWord)) {
return false;
}
mInputMode.skipNextTextCaseDetection();
settings.saveTextCase(mInputMode.getTextCase());
// if there are no suggestions or they are special chars, we don't need to adjust their text case
final String currentWord = suggestionOps.isEmpty() || mInputMode.getSequence().isEmpty() ? "" : suggestionOps.getCurrent();
if (currentWord.isEmpty() || !Character.isAlphabetic(currentWord.charAt(0))) {
settings.saveTextCase(mInputMode.getTextCase());
if (currentWord.isEmpty() || (currentWord.length() == 1 && !Character.isAlphabetic(currentWord.charAt(0)))) {
return true;
}
// When we are in AUTO mode and current dictionary word is in uppercase,
// the mode would switch to UPPERCASE, but visually, the word would not change.
// This is why we retry using the code below, until there is a visual change.
// if there are suggestions, we need to adjust their text case to acknowledge the change
int currentSuggestionIndex = suggestionOps.getCurrentIndex();
currentSuggestionIndex = suggestionOps.containsStem() ? currentSuggestionIndex - 1 : currentSuggestionIndex;
for (int retries = 0; retries <= 2; retries++) {
if (!currentWord.equals(mInputMode.getSuggestions().get(currentSuggestionIndex)) || !mInputMode.nextTextCase()) {
break;
}
}
suggestionOps.set(mInputMode.getSuggestions(), currentSuggestionIndex, mInputMode.containsGeneratedSuggestions());
textField.setComposingText(suggestionOps.getCurrent());
settings.saveTextCase(mInputMode.getTextCase());
return true;
}

View file

@ -206,7 +206,7 @@ abstract public class InputMode {
* If "analyzeSurroundingText" is true, and when the mode supports text analyzing, it may apply
* additional logic to determine the next valid text case.
*/
public boolean nextTextCase() {
public boolean nextTextCase(@Nullable String currentWord) {
if (!language.hasUpperCase()) {
return false;
}

View file

@ -30,7 +30,7 @@ public class ModeIdeograms extends ModeWords {
@Override protected String adjustSuggestionTextCase(String word, int newTextCase) { return word; }
@Override public void determineNextWordTextCase(int nextDigit) {}
@Override public boolean nextTextCase() { return false; }
@Override public boolean nextTextCase(@Nullable String currentWord) { return false; }
@Override

View file

@ -382,12 +382,18 @@ class ModeWords extends ModeCheonjiin {
}
@Override
public boolean nextTextCase() {
// convert any internally used text cases to user-friendly, because this is what the user
// is allowed to choose from.
public boolean nextTextCase(@Nullable String currentWord) {
if (currentWord == null || currentWord.isEmpty() || (currentWord.length() == 1 && !Character.isAlphabetic(currentWord.charAt(0)))) {
textCase = getTextCase();
} else {
textCase = new Text(language, currentWord).getTextCase();
}
boolean changed = super.nextTextCase();
// Skip capitalized text for words like: 've, 's, 'll, etc... only allow upper and lower cases.
boolean changed = super.nextTextCase(currentWord);
if (textCase != CASE_LOWER && textCase != CASE_UPPER && currentWord != null && currentWord.length() > 1 && !Character.isAlphabetic(currentWord.charAt(0))) {
changed = super.nextTextCase(currentWord);
}
// since it's a user's choice, the default matters no more
textFieldTextCase = changed ? CASE_UNDEFINED : textFieldTextCase;

View file

@ -36,7 +36,7 @@ public class Text extends TextTools {
public String capitalize() {
if (language == null || text == null || text.isEmpty() || !language.hasUpperCase()) {
if (language == null || text == null || text.isEmpty() || !language.hasUpperCase() || !Character.isAlphabetic(text.charAt(0))) {
return text;
}
@ -141,12 +141,24 @@ public class Text extends TextTools {
return false;
}
if (!Character.isUpperCase(text.charAt(0))) {
return false;
char[] chars = text.toCharArray();
boolean firstLetterFound = false;
for (int i = 0, end = text.length(); i < end; i++) {
if (!Character.isAlphabetic(chars[i])) {
continue;
}
for (int i = 1, end = text.length(); i < end; i++) {
if (Character.isUpperCase(text.charAt(i))) {
if (!firstLetterFound) {
if (Character.isUpperCase(chars[i])) {
firstLetterFound = true;
continue;
} else {
return false;
}
}
if (Character.isUpperCase(chars[i])) {
return false;
}
}