mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Merge "Pull up common code in the consolidated method (A76)"
This commit is contained in:
commit
75e605f7ca
@ -1675,35 +1675,36 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||||||
}
|
}
|
||||||
|
|
||||||
final String typedWord = mWordComposer.getTypedWord();
|
final String typedWord = mWordComposer.getTypedWord();
|
||||||
final SuggestedWords suggestions;
|
|
||||||
if (!mWordComposer.isComposingWord() && !mCurrentSettings.mBigramPredictionEnabled) {
|
if (!mWordComposer.isComposingWord() && !mCurrentSettings.mBigramPredictionEnabled) {
|
||||||
setPunctuationSuggestions();
|
setPunctuationSuggestions();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mWordComposer.isComposingWord()) {
|
// Get the word on which we should search the bigrams. If we are composing a word, it's
|
||||||
suggestions = updateBigramPredictions();
|
// whatever is *before* the half-committed word in the buffer, hence 2; if we aren't, we
|
||||||
} else {
|
// should just skip whitespace if any, so 1.
|
||||||
suggestions = updateSuggestions(typedWord);
|
// TODO: this is slow (2-way IPC) - we should probably cache this instead.
|
||||||
|
final CharSequence prevWord =
|
||||||
|
mConnection.getNthPreviousWord(mCurrentSettings.mWordSeparators,
|
||||||
|
mWordComposer.isComposingWord() ? 2 : 1);
|
||||||
|
SuggestedWords suggestedWords = mSuggest.getSuggestedWords(mWordComposer,
|
||||||
|
prevWord, mKeyboardSwitcher.getKeyboard().getProximityInfo(),
|
||||||
|
mCurrentSettings.mCorrectionEnabled, !mWordComposer.isComposingWord());
|
||||||
|
|
||||||
|
if (mWordComposer.isComposingWord()) {
|
||||||
|
suggestedWords = maybeRetrieveOlderSuggestions(typedWord, suggestedWords);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null != suggestions && suggestions.size() > 0) {
|
if (null != suggestedWords && suggestedWords.size() > 0) {
|
||||||
showSuggestions(suggestions, typedWord);
|
showSuggestions(suggestedWords, typedWord);
|
||||||
} else {
|
} else {
|
||||||
clearSuggestions();
|
clearSuggestions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private SuggestedWords updateSuggestions(final CharSequence typedWord) {
|
private SuggestedWords maybeRetrieveOlderSuggestions(final CharSequence typedWord,
|
||||||
// TODO: May need a better way of retrieving previous word
|
final SuggestedWords suggestedWords) {
|
||||||
final CharSequence prevWord =
|
// TODO: consolidate this into getSuggestedWords
|
||||||
mConnection.getNthPreviousWord(mCurrentSettings.mWordSeparators, 2);
|
|
||||||
// getSuggestedWords handles gracefully a null value of prevWord
|
|
||||||
final SuggestedWords suggestedWords = mSuggest.getSuggestedWords(mWordComposer,
|
|
||||||
prevWord, mKeyboardSwitcher.getKeyboard().getProximityInfo(),
|
|
||||||
// !mWordComposer.isComposingWord() is known to be false
|
|
||||||
mCurrentSettings.mCorrectionEnabled, !mWordComposer.isComposingWord());
|
|
||||||
|
|
||||||
// Basically, we update the suggestion strip only when suggestion count > 1. However,
|
// Basically, we update the suggestion strip only when suggestion count > 1. However,
|
||||||
// there is an exception: We update the suggestion strip whenever typed word's length
|
// there is an exception: We update the suggestion strip whenever typed word's length
|
||||||
// is 1 or typed word is found in dictionary, regardless of suggestion count. Actually,
|
// is 1 or typed word is found in dictionary, regardless of suggestion count. Actually,
|
||||||
@ -1891,15 +1892,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||||||
separatorCode, prevWord);
|
separatorCode, prevWord);
|
||||||
}
|
}
|
||||||
|
|
||||||
private SuggestedWords updateBigramPredictions() {
|
|
||||||
final CharSequence prevWord =
|
|
||||||
mConnection.getNthPreviousWord(mCurrentSettings.mWordSeparators, 1);
|
|
||||||
return mSuggest.getSuggestedWords(mWordComposer,
|
|
||||||
prevWord, mKeyboardSwitcher.getKeyboard().getProximityInfo(),
|
|
||||||
// !mWordComposer.isComposingWord() is known to be true
|
|
||||||
mCurrentSettings.mCorrectionEnabled, !mWordComposer.isComposingWord());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPunctuationSuggestions() {
|
public void setPunctuationSuggestions() {
|
||||||
if (mCurrentSettings.mBigramPredictionEnabled) {
|
if (mCurrentSettings.mBigramPredictionEnabled) {
|
||||||
clearSuggestions();
|
clearSuggestions();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user