1
0
Fork 0

Fixed the "il n'y a pas" problem. Single letters were sometimes suggested in alphabetic order instead of by popularity, when typing them right after a punctuation mark.

This commit is contained in:
sspanak 2024-08-31 15:30:43 +03:00 committed by Dimo Karaivanov
parent a7a09c0603
commit 266bed96db
4 changed files with 34 additions and 17 deletions

View file

@ -187,7 +187,9 @@ public abstract class HotkeyHandler extends CommandHandler {
suggestionOps.cancelDelayedAccept();
if (mInputMode.clearWordStem()) {
mInputMode.loadSuggestions(this::getSuggestions, suggestionOps.getCurrent(mInputMode.getSequenceLength()));
mInputMode
.setOnSuggestionsUpdated(this::getSuggestions)
.loadSuggestions(suggestionOps.getCurrent(mInputMode.getSequenceLength()));
return true;
}
@ -219,7 +221,9 @@ public abstract class HotkeyHandler extends CommandHandler {
if (filter.isEmpty()) {
mInputMode.reset();
} else if (mInputMode.setWordStem(filter, repeat)) {
mInputMode.loadSuggestions(super::getSuggestions, filter);
mInputMode
.setOnSuggestionsUpdated(super::getSuggestions)
.loadSuggestions(filter);
}
return true;

View file

@ -313,7 +313,7 @@ public abstract class TypingHandler extends KeyPadHandler {
protected void onAcceptSuggestionAutomatically(String word) {
mInputMode.onAcceptSuggestion(word, true);
autoCorrectSpace(word, false, -1);
autoCorrectSpace(word, false, mInputMode.getSequence().isEmpty() ? -1 : mInputMode.getSequence().charAt(0) - '0');
mInputMode.determineNextWordTextCase(textField.getStringBeforeCursor());
}
@ -341,7 +341,9 @@ public abstract class TypingHandler extends KeyPadHandler {
mInputMode.reset();
UI.toastShortSingle(this, R.string.dictionary_loading_please_wait);
} else {
mInputMode.loadSuggestions(this::handleSuggestions, suggestionOps.getCurrent());
mInputMode
.setOnSuggestionsUpdated(this::handleSuggestions)
.loadSuggestions(suggestionOps.getCurrent());
}
}

View file

@ -33,6 +33,7 @@ abstract public class InputMode {
@NonNull protected String digitSequence = "";
protected Language language;
protected final ArrayList<String> suggestions = new ArrayList<>();
@NonNull protected Runnable onSuggestionsUpdated = () -> {};
protected int specialCharSelectedGroup = 0;
@ -62,11 +63,11 @@ abstract public class InputMode {
/**
* loadSuggestions
* Loads the suggestions based on the current state, with optional "currentWord" filter.
* Once loading is finished the respective InputMode child will call "onLoad", notifying it
* the suggestions are available using "getSuggestions()".
* Once loading is finished the respective InputMode child will call the Runnable set with
* "setOnSuggestionsUpdated()", notifying it the suggestions are available using "getSuggestions()".
*/
public void loadSuggestions(Runnable onLoad, String currentWord) {
onLoad.run();
public void loadSuggestions(String currentWord) {
onSuggestionsUpdated.run();
}
public ArrayList<String> getSuggestions() {
@ -78,6 +79,11 @@ abstract public class InputMode {
return newSuggestions;
}
public InputMode setOnSuggestionsUpdated(@NonNull Runnable onSuggestionsUpdated) {
this.onSuggestionsUpdated = onSuggestionsUpdated;
return this;
}
// Numeric mode identifiers. "instanceof" cannot be used in all cases, because they inherit each other.
public boolean is123() { return false; }
public boolean isPassthrough() { return false; }
@ -86,6 +92,7 @@ abstract public class InputMode {
// Utility
abstract public int getId();
public boolean containsGeneratedSuggestions() { return false; }
public String getSequence() { return digitSequence; }
public int getSequenceLength() { return digitSequence.length(); } // The number of key presses for the current word.
public int getAutoAcceptTimeout() {
return autoAcceptTimeout;

View file

@ -38,7 +38,6 @@ public class ModePredictive extends InputMode {
// async suggestion handling
private boolean disablePredictions = false;
private Runnable onSuggestionsUpdated;
// text analysis tools
private final AutoSpace autoSpace;
@ -171,6 +170,12 @@ public class ModePredictive extends InputMode {
int lastAcceptedWordLength = lastAcceptedWord.length();
digitSequence = digitSequence.length() > lastAcceptedWordLength ? digitSequence.substring(lastAcceptedWordLength) : "";
if (digitSequence.length() == 1) {
suggestions.clear();
loadSuggestions("");
return;
}
ArrayList<String> lastSuggestions = new ArrayList<>(suggestions);
suggestions.clear();
for (String s : lastSuggestions) {
@ -255,19 +260,18 @@ public class ModePredictive extends InputMode {
* See: Predictions.generatePossibleCompletions()
*/
@Override
public void loadSuggestions(Runnable onLoad, String currentWord) {
public void loadSuggestions(String currentWord) {
if (disablePredictions) {
super.loadSuggestions(onLoad, currentWord);
super.loadSuggestions(currentWord);
return;
}
if (loadStaticSuggestions(onLoad)) {
if (loadStaticSuggestions()) {
return;
}
Language searchLanguage = digitSequence.equals(EmojiLanguage.CUSTOM_EMOJI_SEQUENCE) ? new EmojiLanguage() : language;
onSuggestionsUpdated = onLoad;
predictions
.setDigitSequence(digitSequence)
.setIsStemFuzzy(isStemFuzzy)
@ -284,20 +288,20 @@ public class ModePredictive extends InputMode {
* emoji or the preferred character for double "0". Returns "false", when there are no static
* options for the current digitSequence.
*/
private boolean loadStaticSuggestions(Runnable onLoad) {
private boolean loadStaticSuggestions() {
if (digitSequence.equals(NaturalLanguage.PUNCTUATION_KEY) || digitSequence.equals(NaturalLanguage.SPECIAL_CHARS_KEY)) {
loadSpecialCharacters(language);
onLoad.run();
onSuggestionsUpdated.run();
return true;
} else if (!digitSequence.equals(EmojiLanguage.CUSTOM_EMOJI_SEQUENCE) && digitSequence.startsWith(EmojiLanguage.EMOJI_SEQUENCE)) {
suggestions.clear();
suggestions.addAll(new EmojiLanguage().getKeyCharacters(digitSequence.charAt(0) - '0', digitSequence.length() - 2));
onLoad.run();
onSuggestionsUpdated.run();
return true;
} else if (digitSequence.startsWith(NaturalLanguage.PREFERRED_CHAR_SEQUENCE)) {
suggestions.clear();
suggestions.add(settings.getDoubleZeroChar());
onLoad.run();
onSuggestionsUpdated.run();
return true;
}