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

View file

@ -313,7 +313,7 @@ public abstract class TypingHandler extends KeyPadHandler {
protected void onAcceptSuggestionAutomatically(String word) { protected void onAcceptSuggestionAutomatically(String word) {
mInputMode.onAcceptSuggestion(word, true); mInputMode.onAcceptSuggestion(word, true);
autoCorrectSpace(word, false, -1); autoCorrectSpace(word, false, mInputMode.getSequence().isEmpty() ? -1 : mInputMode.getSequence().charAt(0) - '0');
mInputMode.determineNextWordTextCase(textField.getStringBeforeCursor()); mInputMode.determineNextWordTextCase(textField.getStringBeforeCursor());
} }
@ -341,7 +341,9 @@ public abstract class TypingHandler extends KeyPadHandler {
mInputMode.reset(); mInputMode.reset();
UI.toastShortSingle(this, R.string.dictionary_loading_please_wait); UI.toastShortSingle(this, R.string.dictionary_loading_please_wait);
} else { } 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 = ""; @NonNull protected String digitSequence = "";
protected Language language; protected Language language;
protected final ArrayList<String> suggestions = new ArrayList<>(); protected final ArrayList<String> suggestions = new ArrayList<>();
@NonNull protected Runnable onSuggestionsUpdated = () -> {};
protected int specialCharSelectedGroup = 0; protected int specialCharSelectedGroup = 0;
@ -62,11 +63,11 @@ abstract public class InputMode {
/** /**
* loadSuggestions * loadSuggestions
* Loads the suggestions based on the current state, with optional "currentWord" filter. * 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 * Once loading is finished the respective InputMode child will call the Runnable set with
* the suggestions are available using "getSuggestions()". * "setOnSuggestionsUpdated()", notifying it the suggestions are available using "getSuggestions()".
*/ */
public void loadSuggestions(Runnable onLoad, String currentWord) { public void loadSuggestions(String currentWord) {
onLoad.run(); onSuggestionsUpdated.run();
} }
public ArrayList<String> getSuggestions() { public ArrayList<String> getSuggestions() {
@ -78,6 +79,11 @@ abstract public class InputMode {
return newSuggestions; 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. // Numeric mode identifiers. "instanceof" cannot be used in all cases, because they inherit each other.
public boolean is123() { return false; } public boolean is123() { return false; }
public boolean isPassthrough() { return false; } public boolean isPassthrough() { return false; }
@ -86,6 +92,7 @@ abstract public class InputMode {
// Utility // Utility
abstract public int getId(); abstract public int getId();
public boolean containsGeneratedSuggestions() { return false; } 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 getSequenceLength() { return digitSequence.length(); } // The number of key presses for the current word.
public int getAutoAcceptTimeout() { public int getAutoAcceptTimeout() {
return autoAcceptTimeout; return autoAcceptTimeout;

View file

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