1
0
Fork 0

fixed suggestion selection getting reset when toggling the text case of generated suggestions

This commit is contained in:
sspanak 2024-09-03 18:39:00 +03:00 committed by Dimo Karaivanov
parent d99e930fda
commit b71ed8c705
3 changed files with 25 additions and 14 deletions

View file

@ -153,27 +153,27 @@ abstract public class CommandHandler extends TextEditingHandler {
protected void nextTextCase() {
String currentSuggestionBefore = suggestionOps.getCurrent();
int currentSuggestionIndex = suggestionOps.getCurrentIndex();
// 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.
// This is why we retry, until there is a visual change.
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);
// this is a word and the text case has finally changed
if (!firstSuggestionAfter.equalsIgnoreCase(suggestionOps.get(0))) {
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 (currentSuggestionAfter.isEmpty() || !currentSuggestionBefore.equalsIgnoreCase(currentSuggestionAfter)) {
if (!Character.isAlphabetic(mInputMode.getSuggestions().get(0).charAt(0))) {
currentSuggestionIndex = 0;
break;
}
// the suggestion list is the same and the text case is different, so let's use it
if (!currentSuggestionBefore.equals(currentSuggestionAfter)) {
break;
}
}
suggestionOps.set(mInputMode.getSuggestions(), currentSuggestionIndex, mInputMode.containsGeneratedSuggestions());

View file

@ -38,6 +38,11 @@ public class SuggestionOps {
}
public boolean containsStem() {
return suggestionBar.containsStem();
}
public String get(int index) {
return suggestionBar.getSuggestion(index);
}

View file

@ -110,6 +110,11 @@ public class SuggestionsBar {
}
public boolean containsStem() {
return !stem.isEmpty();
}
public int getCurrentIndex() {
return selectedIndex;
}
@ -141,6 +146,7 @@ public class SuggestionsBar {
setStem(newSuggestions, containsGenerated);
addAllSuggestions(newSuggestions);
selectedIndex = Math.min(selectedIndex, suggestions.size() - 1);
setSuggestionsOnScreen();
}