Merge "When starting input, include the literal word in suggestions"
commit
6464d73ad9
|
@ -166,6 +166,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
private static final int ARG1_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT = 1;
|
private static final int ARG1_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT = 1;
|
||||||
private static final int ARG1_SHOW_GESTURE_FLOATING_PREVIEW_TEXT = 2;
|
private static final int ARG1_SHOW_GESTURE_FLOATING_PREVIEW_TEXT = 2;
|
||||||
private static final int ARG2_UNUSED = 0;
|
private static final int ARG2_UNUSED = 0;
|
||||||
|
private static final int ARG1_FALSE = 0;
|
||||||
|
private static final int ARG1_TRUE = 1;
|
||||||
|
|
||||||
private int mDelayUpdateSuggestions;
|
private int mDelayUpdateSuggestions;
|
||||||
private int mDelayUpdateShiftState;
|
private int mDelayUpdateShiftState;
|
||||||
|
@ -213,7 +215,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
case MSG_RESUME_SUGGESTIONS:
|
case MSG_RESUME_SUGGESTIONS:
|
||||||
latinIme.mInputLogic.restartSuggestionsOnWordTouchedByCursor(
|
latinIme.mInputLogic.restartSuggestionsOnWordTouchedByCursor(
|
||||||
latinIme.mSettings.getCurrent(),
|
latinIme.mSettings.getCurrent(),
|
||||||
false /* includeResumedWordInSuggestions */);
|
msg.arg1 == ARG1_TRUE /* shouldIncludeResumedWordInSuggestions */);
|
||||||
break;
|
break;
|
||||||
case MSG_REOPEN_DICTIONARIES:
|
case MSG_REOPEN_DICTIONARIES:
|
||||||
latinIme.resetSuggest();
|
latinIme.resetSuggest();
|
||||||
|
@ -250,7 +252,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
sendMessage(obtainMessage(MSG_REOPEN_DICTIONARIES));
|
sendMessage(obtainMessage(MSG_REOPEN_DICTIONARIES));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void postResumeSuggestions() {
|
public void postResumeSuggestions(final boolean shouldIncludeResumedWordInSuggestions) {
|
||||||
final LatinIME latinIme = getOwnerInstance();
|
final LatinIME latinIme = getOwnerInstance();
|
||||||
if (latinIme == null) {
|
if (latinIme == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -260,7 +262,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
removeMessages(MSG_RESUME_SUGGESTIONS);
|
removeMessages(MSG_RESUME_SUGGESTIONS);
|
||||||
sendMessageDelayed(obtainMessage(MSG_RESUME_SUGGESTIONS), mDelayUpdateSuggestions);
|
sendMessageDelayed(obtainMessage(MSG_RESUME_SUGGESTIONS,
|
||||||
|
shouldIncludeResumedWordInSuggestions ? ARG1_TRUE : ARG1_FALSE,
|
||||||
|
0 /* ignored */),
|
||||||
|
mDelayUpdateSuggestions);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void postResetCaches(final boolean tryResumeSuggestions, final int remainingTries) {
|
public void postResetCaches(final boolean tryResumeSuggestions, final int remainingTries) {
|
||||||
|
@ -809,7 +814,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
// When rotating, initialSelStart and initialSelEnd sometimes are lying. Make a best
|
// When rotating, initialSelStart and initialSelEnd sometimes are lying. Make a best
|
||||||
// effort to work around this bug.
|
// effort to work around this bug.
|
||||||
mInputLogic.mConnection.tryFixLyingCursorPosition();
|
mInputLogic.mConnection.tryFixLyingCursorPosition();
|
||||||
mHandler.postResumeSuggestions();
|
mHandler.postResumeSuggestions(true /* shouldIncludeResumedWordInSuggestions */);
|
||||||
canReachInputConnection = true;
|
canReachInputConnection = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -356,7 +356,7 @@ public final class InputLogic {
|
||||||
// The cursor has been moved : we now accept to perform recapitalization
|
// The cursor has been moved : we now accept to perform recapitalization
|
||||||
mRecapitalizeStatus.enable();
|
mRecapitalizeStatus.enable();
|
||||||
// We moved the cursor. If we are touching a word, we need to resume suggestion.
|
// We moved the cursor. If we are touching a word, we need to resume suggestion.
|
||||||
mLatinIME.mHandler.postResumeSuggestions();
|
mLatinIME.mHandler.postResumeSuggestions(false /* shouldIncludeResumedWordInSuggestions */);
|
||||||
// Stop the last recapitalization, if started.
|
// Stop the last recapitalization, if started.
|
||||||
mRecapitalizeStatus.stop();
|
mRecapitalizeStatus.stop();
|
||||||
return true;
|
return true;
|
||||||
|
@ -998,7 +998,7 @@ public final class InputLogic {
|
||||||
&& !mConnection.isCursorFollowedByWordCharacter(
|
&& !mConnection.isCursorFollowedByWordCharacter(
|
||||||
inputTransaction.mSettingsValues.mSpacingAndPunctuations)) {
|
inputTransaction.mSettingsValues.mSpacingAndPunctuations)) {
|
||||||
restartSuggestionsOnWordTouchedByCursor(inputTransaction.mSettingsValues,
|
restartSuggestionsOnWordTouchedByCursor(inputTransaction.mSettingsValues,
|
||||||
true /* includeResumedWordInSuggestions */);
|
true /* shouldIncludeResumedWordInSuggestions */);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1238,12 +1238,12 @@ public final class InputLogic {
|
||||||
* do nothing.
|
* do nothing.
|
||||||
*
|
*
|
||||||
* @param settingsValues the current values of the settings.
|
* @param settingsValues the current values of the settings.
|
||||||
* @param includeResumedWordInSuggestions whether to include the word on which we resume
|
* @param shouldIncludeResumedWordInSuggestions whether to include the word on which we resume
|
||||||
* suggestions in the suggestion list.
|
* suggestions in the suggestion list.
|
||||||
*/
|
*/
|
||||||
// TODO: make this private.
|
// TODO: make this private.
|
||||||
public void restartSuggestionsOnWordTouchedByCursor(final SettingsValues settingsValues,
|
public void restartSuggestionsOnWordTouchedByCursor(final SettingsValues settingsValues,
|
||||||
final boolean includeResumedWordInSuggestions) {
|
final boolean shouldIncludeResumedWordInSuggestions) {
|
||||||
// HACK: We may want to special-case some apps that exhibit bad behavior in case of
|
// HACK: We may want to special-case some apps that exhibit bad behavior in case of
|
||||||
// recorrection. This is a temporary, stopgap measure that will be removed later.
|
// recorrection. This is a temporary, stopgap measure that will be removed later.
|
||||||
// TODO: remove this.
|
// TODO: remove this.
|
||||||
|
@ -1289,7 +1289,7 @@ public final class InputLogic {
|
||||||
if (numberOfCharsInWordBeforeCursor > expectedCursorPosition) return;
|
if (numberOfCharsInWordBeforeCursor > expectedCursorPosition) return;
|
||||||
final ArrayList<SuggestedWordInfo> suggestions = new ArrayList<>();
|
final ArrayList<SuggestedWordInfo> suggestions = new ArrayList<>();
|
||||||
final String typedWord = range.mWord.toString();
|
final String typedWord = range.mWord.toString();
|
||||||
if (includeResumedWordInSuggestions) {
|
if (shouldIncludeResumedWordInSuggestions) {
|
||||||
suggestions.add(new SuggestedWordInfo(typedWord,
|
suggestions.add(new SuggestedWordInfo(typedWord,
|
||||||
SuggestedWords.MAX_SUGGESTIONS + 1,
|
SuggestedWords.MAX_SUGGESTIONS + 1,
|
||||||
SuggestedWordInfo.KIND_TYPED, Dictionary.DICTIONARY_USER_TYPED,
|
SuggestedWordInfo.KIND_TYPED, Dictionary.DICTIONARY_USER_TYPED,
|
||||||
|
@ -1327,9 +1327,10 @@ public final class InputLogic {
|
||||||
typedWord.codePointCount(0, numberOfCharsInWordBeforeCursor));
|
typedWord.codePointCount(0, numberOfCharsInWordBeforeCursor));
|
||||||
mConnection.setComposingRegion(expectedCursorPosition - numberOfCharsInWordBeforeCursor,
|
mConnection.setComposingRegion(expectedCursorPosition - numberOfCharsInWordBeforeCursor,
|
||||||
expectedCursorPosition + range.getNumberOfCharsInWordAfterCursor());
|
expectedCursorPosition + range.getNumberOfCharsInWordAfterCursor());
|
||||||
if (suggestions.isEmpty()) {
|
if (suggestions.size() <= (shouldIncludeResumedWordInSuggestions ? 1 : 0)) {
|
||||||
// We come here if there weren't any suggestion spans on this word. We will try to
|
// If there weren't any suggestion spans on this word, suggestions#size() will be 1
|
||||||
// compute suggestions for it instead.
|
// if shouldIncludeResumedWordInSuggestions is true, 0 otherwise. In this case, we
|
||||||
|
// have no useful suggestions, so we will try to compute some for it instead.
|
||||||
mInputLogicHandler.getSuggestedWords(Suggest.SESSION_TYPING,
|
mInputLogicHandler.getSuggestedWords(Suggest.SESSION_TYPING,
|
||||||
SuggestedWords.NOT_A_SEQUENCE_NUMBER, new OnGetSuggestedWordsCallback() {
|
SuggestedWords.NOT_A_SEQUENCE_NUMBER, new OnGetSuggestedWordsCallback() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -1337,7 +1338,7 @@ public final class InputLogic {
|
||||||
final SuggestedWords suggestedWordsIncludingTypedWord) {
|
final SuggestedWords suggestedWordsIncludingTypedWord) {
|
||||||
final SuggestedWords suggestedWords;
|
final SuggestedWords suggestedWords;
|
||||||
if (suggestedWordsIncludingTypedWord.size() > 1
|
if (suggestedWordsIncludingTypedWord.size() > 1
|
||||||
&& !includeResumedWordInSuggestions) {
|
&& !shouldIncludeResumedWordInSuggestions) {
|
||||||
// We were able to compute new suggestions for this word.
|
// We were able to compute new suggestions for this word.
|
||||||
// Remove the typed word, since we don't want to display it in this
|
// Remove the typed word, since we don't want to display it in this
|
||||||
// case. The #getSuggestedWordsExcludingTypedWord() method sets
|
// case. The #getSuggestedWordsExcludingTypedWord() method sets
|
||||||
|
@ -1944,7 +1945,9 @@ public final class InputLogic {
|
||||||
}
|
}
|
||||||
mConnection.tryFixLyingCursorPosition();
|
mConnection.tryFixLyingCursorPosition();
|
||||||
if (tryResumeSuggestions) {
|
if (tryResumeSuggestions) {
|
||||||
handler.postResumeSuggestions();
|
// This is triggered when starting input anew, so we want to include the resumed
|
||||||
|
// word in suggestions.
|
||||||
|
handler.postResumeSuggestions(true /* shouldIncludeResumedWordInSuggestions */);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue