fixed suggestion selection getting reset when toggling the text case of generated suggestions
This commit is contained in:
parent
d99e930fda
commit
b71ed8c705
3 changed files with 25 additions and 14 deletions
|
|
@ -153,29 +153,29 @@ abstract public class CommandHandler extends TextEditingHandler {
|
||||||
|
|
||||||
|
|
||||||
protected void nextTextCase() {
|
protected void nextTextCase() {
|
||||||
String currentSuggestionBefore = suggestionOps.getCurrent();
|
|
||||||
int currentSuggestionIndex = suggestionOps.getCurrentIndex();
|
|
||||||
|
|
||||||
// When we are in AUTO mode and the dictionary word is in uppercase,
|
// When we are in AUTO mode and the 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.
|
||||||
for (int retries = 0; retries < 2 && mInputMode.nextTextCase(); retries++) {
|
for (int retries = 0; retries < 2 && mInputMode.nextTextCase(); retries++) {
|
||||||
String currentSuggestionAfter = mInputMode.getSuggestions().size() >= suggestionOps.getCurrentIndex() ? mInputMode.getSuggestions().get(suggestionOps.getCurrentIndex()) : "";
|
String firstSuggestionAfter = mInputMode.getSuggestions().get(0);
|
||||||
// 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
|
|
||||||
// list is shorter, the "before" index may be invalid, so "after" would be empty.
|
|
||||||
// In these cases, we scroll to the first one, for consistency.
|
|
||||||
if (currentSuggestionAfter.isEmpty() || !currentSuggestionBefore.equalsIgnoreCase(currentSuggestionAfter)) {
|
|
||||||
currentSuggestionIndex = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// the suggestion list is the same and the text case is different, so let's use it
|
// this is a word and the text case has finally changed
|
||||||
if (!currentSuggestionBefore.equals(currentSuggestionAfter)) {
|
if (!firstSuggestionAfter.equalsIgnoreCase(suggestionOps.get(0))) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int currentSuggestionIndex = suggestionOps.getCurrentIndex();
|
||||||
|
currentSuggestionIndex = suggestionOps.containsStem() ? currentSuggestionIndex - 1 : currentSuggestionIndex;
|
||||||
|
|
||||||
|
// 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
|
||||||
|
// list is shorter, the "before" index may be invalid, so "after" would be empty.
|
||||||
|
// In these cases, we scroll to the first one, for consistency.
|
||||||
|
if (!Character.isAlphabetic(mInputMode.getSuggestions().get(0).charAt(0))) {
|
||||||
|
currentSuggestionIndex = 0;
|
||||||
|
}
|
||||||
|
|
||||||
suggestionOps.set(mInputMode.getSuggestions(), currentSuggestionIndex, mInputMode.containsGeneratedSuggestions());
|
suggestionOps.set(mInputMode.getSuggestions(), currentSuggestionIndex, mInputMode.containsGeneratedSuggestions());
|
||||||
textField.setComposingText(suggestionOps.getCurrent());
|
textField.setComposingText(suggestionOps.getCurrent());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,11 @@ public class SuggestionOps {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean containsStem() {
|
||||||
|
return suggestionBar.containsStem();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public String get(int index) {
|
public String get(int index) {
|
||||||
return suggestionBar.getSuggestion(index);
|
return suggestionBar.getSuggestion(index);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,11 @@ public class SuggestionsBar {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean containsStem() {
|
||||||
|
return !stem.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public int getCurrentIndex() {
|
public int getCurrentIndex() {
|
||||||
return selectedIndex;
|
return selectedIndex;
|
||||||
}
|
}
|
||||||
|
|
@ -141,6 +146,7 @@ public class SuggestionsBar {
|
||||||
|
|
||||||
setStem(newSuggestions, containsGenerated);
|
setStem(newSuggestions, containsGenerated);
|
||||||
addAllSuggestions(newSuggestions);
|
addAllSuggestions(newSuggestions);
|
||||||
|
selectedIndex = Math.min(selectedIndex, suggestions.size() - 1);
|
||||||
setSuggestionsOnScreen();
|
setSuggestionsOnScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue