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:
parent
548041be28
commit
1aa68eca60
5 changed files with 37 additions and 28 deletions
|
|
@ -209,36 +209,27 @@ abstract public class CommandHandler extends TextEditingHandler {
|
||||||
|
|
||||||
|
|
||||||
protected boolean nextTextCase() {
|
protected boolean nextTextCase() {
|
||||||
if (!mInputMode.nextTextCase()) {
|
final String currentWord = suggestionOps.isEmpty() || mInputMode.getSequence().isEmpty() ? "" : suggestionOps.getCurrent();
|
||||||
|
|
||||||
|
if (!mInputMode.nextTextCase(currentWord)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
mInputMode.skipNextTextCaseDetection();
|
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
|
// 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() || (currentWord.length() == 1 && !Character.isAlphabetic(currentWord.charAt(0)))) {
|
||||||
if (currentWord.isEmpty() || !Character.isAlphabetic(currentWord.charAt(0))) {
|
|
||||||
settings.saveTextCase(mInputMode.getTextCase());
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// When we are in AUTO mode and current dictionary word is in uppercase,
|
// if there are suggestions, we need to adjust their text case to acknowledge the change
|
||||||
// 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.
|
|
||||||
int currentSuggestionIndex = suggestionOps.getCurrentIndex();
|
int currentSuggestionIndex = suggestionOps.getCurrentIndex();
|
||||||
currentSuggestionIndex = suggestionOps.containsStem() ? currentSuggestionIndex - 1 : currentSuggestionIndex;
|
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());
|
suggestionOps.set(mInputMode.getSuggestions(), currentSuggestionIndex, mInputMode.containsGeneratedSuggestions());
|
||||||
textField.setComposingText(suggestionOps.getCurrent());
|
textField.setComposingText(suggestionOps.getCurrent());
|
||||||
|
|
||||||
settings.saveTextCase(mInputMode.getTextCase());
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -206,7 +206,7 @@ abstract public class InputMode {
|
||||||
* If "analyzeSurroundingText" is true, and when the mode supports text analyzing, it may apply
|
* If "analyzeSurroundingText" is true, and when the mode supports text analyzing, it may apply
|
||||||
* additional logic to determine the next valid text case.
|
* additional logic to determine the next valid text case.
|
||||||
*/
|
*/
|
||||||
public boolean nextTextCase() {
|
public boolean nextTextCase(@Nullable String currentWord) {
|
||||||
if (!language.hasUpperCase()) {
|
if (!language.hasUpperCase()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ public class ModeIdeograms extends ModeWords {
|
||||||
|
|
||||||
@Override protected String adjustSuggestionTextCase(String word, int newTextCase) { return word; }
|
@Override protected String adjustSuggestionTextCase(String word, int newTextCase) { return word; }
|
||||||
@Override public void determineNextWordTextCase(int nextDigit) {}
|
@Override public void determineNextWordTextCase(int nextDigit) {}
|
||||||
@Override public boolean nextTextCase() { return false; }
|
@Override public boolean nextTextCase(@Nullable String currentWord) { return false; }
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -382,12 +382,18 @@ class ModeWords extends ModeCheonjiin {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean nextTextCase() {
|
public boolean nextTextCase(@Nullable String currentWord) {
|
||||||
// convert any internally used text cases to user-friendly, because this is what the user
|
if (currentWord == null || currentWord.isEmpty() || (currentWord.length() == 1 && !Character.isAlphabetic(currentWord.charAt(0)))) {
|
||||||
// is allowed to choose from.
|
|
||||||
textCase = getTextCase();
|
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
|
// since it's a user's choice, the default matters no more
|
||||||
textFieldTextCase = changed ? CASE_UNDEFINED : textFieldTextCase;
|
textFieldTextCase = changed ? CASE_UNDEFINED : textFieldTextCase;
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ public class Text extends TextTools {
|
||||||
|
|
||||||
|
|
||||||
public String capitalize() {
|
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;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -141,12 +141,24 @@ public class Text extends TextTools {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Character.isUpperCase(text.charAt(0))) {
|
char[] chars = text.toCharArray();
|
||||||
return false;
|
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 (!firstLetterFound) {
|
||||||
if (Character.isUpperCase(text.charAt(i))) {
|
if (Character.isUpperCase(chars[i])) {
|
||||||
|
firstLetterFound = true;
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Character.isUpperCase(chars[i])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue