textField.getWordBeforeCursor() is no longer called when recomposing is not supported or on every key press (when searching for word pairs)
This commit is contained in:
parent
675c6e9f23
commit
464e2001be
7 changed files with 33 additions and 20 deletions
|
|
@ -147,8 +147,8 @@ public abstract class TypingHandler extends KeyPadHandler {
|
|||
}
|
||||
|
||||
if (settings.getBackspaceRecomposing() && repeat == 0 && suggestionOps.isEmpty() && !DictionaryLoader.getInstance(this).isRunning()) {
|
||||
final String previousWord = textField.getWordBeforeCursor(mLanguage, 0, false);
|
||||
if (mInputMode.recompose(previousWord) && textField.recompose(previousWord)) {
|
||||
final String previousWord = mInputMode.recompose();
|
||||
if (textField.recompose(previousWord)) {
|
||||
getSuggestions(previousWord);
|
||||
} else {
|
||||
mInputMode.reset();
|
||||
|
|
|
|||
|
|
@ -252,7 +252,7 @@ public class TextField extends InputField {
|
|||
* the given "text". Returns "true" if the operation was successful, "false" otherwise.
|
||||
*/
|
||||
public boolean recompose(String text) {
|
||||
if (connection == null || !isComposingSupported) {
|
||||
if (text == null || connection == null || !isComposingSupported) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ abstract public class InputMode {
|
|||
public boolean shouldReplaceLastLetter(int nextKey, boolean hold) { return false; }
|
||||
public boolean shouldSelectNextSuggestion() { return false; }
|
||||
|
||||
public boolean recompose(String word) { return false; }
|
||||
public String recompose() { return null; }
|
||||
public void replaceLastLetter() {}
|
||||
|
||||
public void reset() {
|
||||
|
|
|
|||
|
|
@ -133,27 +133,28 @@ class ModeWords extends ModeCheonjiin {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean recompose(String word) {
|
||||
public String recompose() {
|
||||
if (!language.hasSpaceBetweenWords() || language.isTranscribed()) {
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
if (word == null || word.length() < 2 || word.contains(" ")) {
|
||||
Logger.d(LOG_TAG, "Not recomposing invalid word: '" + word + "'");
|
||||
String previousWord = textField.getWordBeforeCursor(language, 0, false);
|
||||
if (previousWord.length() < 2 || previousWord.contains(" ")) {
|
||||
Logger.d(LOG_TAG, "Not recomposing invalid word: '" + previousWord + "'");
|
||||
textCase = settings.getTextCase();
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
reset();
|
||||
digitSequence = language.getDigitSequenceForWord(word);
|
||||
textCase = new Text(language, word).getTextCase();
|
||||
digitSequence = language.getDigitSequenceForWord(previousWord);
|
||||
textCase = new Text(language, previousWord).getTextCase();
|
||||
} catch (InvalidLanguageCharactersException e) {
|
||||
Logger.d(LOG_TAG, "Not recomposing word: '" + word + "'. " + e.getMessage());
|
||||
return false;
|
||||
Logger.d(LOG_TAG, "Not recomposing word: '" + previousWord + "'. " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
|
||||
return true;
|
||||
return previousWord;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ public class IdeogramPredictions extends WordPredictions {
|
|||
|
||||
@Override
|
||||
@NonNull
|
||||
protected String getWordBeforeCursor(@NonNull String currentWord) {
|
||||
protected String getPenultimateWord(@NonNull String currentWord) {
|
||||
int currentWordLength = currentWord.length();
|
||||
int lastWordLength = lastTypedWord.length();
|
||||
int requiredTextLength = currentWordLength + lastWordLength;
|
||||
|
|
@ -97,7 +97,7 @@ public class IdeogramPredictions extends WordPredictions {
|
|||
return;
|
||||
}
|
||||
|
||||
String previousWord = getWordBeforeCursor(nativeWord);
|
||||
String previousWord = getPenultimateWord(nativeWord);
|
||||
if (previousWord.equals(lastTypedWord)) {
|
||||
// Logger.d("LOG_TAG", "====+> Pairing words: " + previousWord + " + " + nativeWord);
|
||||
DataStore.addWordPair(language, previousWord, nativeWord, sequence);
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ abstract public class Predictions {
|
|||
}
|
||||
|
||||
|
||||
public Predictions setDigitSequence(String digitSequence) {
|
||||
public Predictions setDigitSequence(@NonNull String digitSequence) {
|
||||
this.digitSequence = digitSequence;
|
||||
return this;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,17 +20,27 @@ public class WordPredictions extends Predictions {
|
|||
private boolean isStemFuzzy;
|
||||
|
||||
private String lastEnforcedTopWord;
|
||||
protected String penultimateWord;
|
||||
|
||||
|
||||
public WordPredictions(SettingsStore settings, TextField textField) {
|
||||
super(settings);
|
||||
lastEnforcedTopWord = "";
|
||||
localeWordsSorter = new LocaleWordsSorter(null);
|
||||
penultimateWord = "";
|
||||
stem = "";
|
||||
this.textField = textField;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Predictions setDigitSequence(@NonNull String digitSequence) {
|
||||
if (digitSequence.length() == 1 || digitSequence.equals(this.digitSequence)) {
|
||||
penultimateWord = ""; // enforce reloading the penultimate word
|
||||
}
|
||||
return super.setDigitSequence(digitSequence);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Predictions setLanguage(@NonNull Language language) {
|
||||
super.setLanguage(language);
|
||||
|
|
@ -296,7 +306,9 @@ public class WordPredictions extends Predictions {
|
|||
}
|
||||
|
||||
ArrayList<String> rearrangedWords = new ArrayList<>();
|
||||
String penultimateWord = getWordBeforeCursor(words.get(0));
|
||||
if (penultimateWord.isEmpty()) {
|
||||
penultimateWord = getPenultimateWord(words.get(0));
|
||||
}
|
||||
|
||||
String pairWord = DataStore.getWord2(language, penultimateWord, digitSequence);
|
||||
int morePopularIndex = TextTools.indexOfIgnoreCase(words, pairWord);
|
||||
|
|
@ -324,7 +336,7 @@ public class WordPredictions extends Predictions {
|
|||
*/
|
||||
protected void pairWithPreviousWord(@NonNull String word, @NonNull String sequence) {
|
||||
if (settings.getPredictWordPairs() && sequence.length() == digitSequence.length()) {
|
||||
DataStore.addWordPair(language, getWordBeforeCursor(word), word, sequence);
|
||||
DataStore.addWordPair(language, getPenultimateWord(word), word, sequence);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -334,7 +346,7 @@ public class WordPredictions extends Predictions {
|
|||
* we have a separate method for that.
|
||||
*/
|
||||
@NonNull
|
||||
protected String getWordBeforeCursor(@NonNull String currentWord) {
|
||||
protected String getPenultimateWord(@NonNull String currentWord) {
|
||||
return textField.getWordBeforeCursor(language, 1, true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue