fixed a crash when changing the text case when there are no suggestions
This commit is contained in:
parent
7bab31c2ec
commit
3a5263ccf6
1 changed files with 13 additions and 8 deletions
|
|
@ -174,14 +174,20 @@ abstract public class CommandHandler extends TextEditingHandler {
|
||||||
|
|
||||||
|
|
||||||
protected void nextTextCase() {
|
protected void nextTextCase() {
|
||||||
// When we are in AUTO mode and the dictionary word is in uppercase,
|
if (suggestionOps.isEmpty() || mInputMode.getSuggestions().isEmpty()) {
|
||||||
|
// When there are no suggestions, there is no need to execute the code for
|
||||||
|
// adjusting them below.
|
||||||
|
mInputMode.nextTextCase();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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.
|
// the mode would switch to UPPERCASE, but visually, the word would not change.
|
||||||
// This is why we retry, until there is a visual change.
|
// This is why we retry, until there is a visual change.
|
||||||
|
String before = suggestionOps.get(0);
|
||||||
for (int retries = 0; retries < 2 && mInputMode.nextTextCase(); retries++) {
|
for (int retries = 0; retries < 2 && mInputMode.nextTextCase(); retries++) {
|
||||||
String firstSuggestionAfter = mInputMode.getSuggestions().get(0);
|
String after = mInputMode.getSuggestions().get(0);
|
||||||
|
if (!after.equals(before)) {
|
||||||
// this is a word and the text case has finally changed
|
|
||||||
if (!firstSuggestionAfter.equals(suggestionOps.get(0))) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -190,9 +196,8 @@ abstract public class CommandHandler extends TextEditingHandler {
|
||||||
currentSuggestionIndex = suggestionOps.containsStem() ? currentSuggestionIndex - 1 : currentSuggestionIndex;
|
currentSuggestionIndex = suggestionOps.containsStem() ? currentSuggestionIndex - 1 : currentSuggestionIndex;
|
||||||
|
|
||||||
// If the suggestions are special characters, changing the text case means selecting the
|
// If the suggestions are special characters, changing the text case means selecting the
|
||||||
// next character group. Hence, "before" and "after" are different. Also, if the new suggestion
|
// next character group. It makes no sense to keep the previous selection for a completely
|
||||||
// list is shorter, the "before" index may be invalid, so "after" would be empty.
|
// different list of characters, that's why we reset it.
|
||||||
// In these cases, we scroll to the first one, for consistency.
|
|
||||||
if (!Character.isAlphabetic(mInputMode.getSuggestions().get(0).charAt(0))) {
|
if (!Character.isAlphabetic(mInputMode.getSuggestions().get(0).charAt(0))) {
|
||||||
currentSuggestionIndex = 0;
|
currentSuggestionIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue