Never include the typed word in recorrections

Bug: 17623275
Change-Id: I2461e5e8baf06fb80a05b87f9d3db7a4d1952a01
main
Jean Chalard 2014-10-01 18:32:02 +09:00
parent 7b673c7265
commit 4c90df7e5b
2 changed files with 11 additions and 32 deletions

View File

@ -247,7 +247,6 @@ 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(),
msg.arg1 == ARG1_TRUE /* shouldIncludeResumedWordInSuggestions */,
latinIme.mKeyboardSwitcher.getCurrentKeyboardScriptId()); latinIme.mKeyboardSwitcher.getCurrentKeyboardScriptId());
break; break;
case MSG_REOPEN_DICTIONARIES: case MSG_REOPEN_DICTIONARIES:
@ -288,8 +287,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
sendMessage(obtainMessage(MSG_REOPEN_DICTIONARIES)); sendMessage(obtainMessage(MSG_REOPEN_DICTIONARIES));
} }
public void postResumeSuggestions(final boolean shouldIncludeResumedWordInSuggestions, public void postResumeSuggestions(final boolean shouldDelay) {
final boolean shouldDelay) {
final LatinIME latinIme = getOwnerInstance(); final LatinIME latinIme = getOwnerInstance();
if (latinIme == null) { if (latinIme == null) {
return; return;
@ -299,13 +297,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} }
removeMessages(MSG_RESUME_SUGGESTIONS); removeMessages(MSG_RESUME_SUGGESTIONS);
if (shouldDelay) { if (shouldDelay) {
sendMessageDelayed(obtainMessage(MSG_RESUME_SUGGESTIONS, sendMessageDelayed(obtainMessage(MSG_RESUME_SUGGESTIONS),
shouldIncludeResumedWordInSuggestions ? ARG1_TRUE : ARG1_FALSE, mDelayInMillisecondsToUpdateSuggestions);
0 /* ignored */), mDelayInMillisecondsToUpdateSuggestions);
} else { } else {
sendMessage(obtainMessage(MSG_RESUME_SUGGESTIONS, sendMessage(obtainMessage(MSG_RESUME_SUGGESTIONS));
shouldIncludeResumedWordInSuggestions ? ARG1_TRUE : ARG1_FALSE,
0 /* ignored */));
} }
} }
@ -622,8 +617,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} }
if (mHandler.hasPendingWaitForDictionaryLoad()) { if (mHandler.hasPendingWaitForDictionaryLoad()) {
mHandler.cancelWaitForDictionaryLoad(); mHandler.cancelWaitForDictionaryLoad();
mHandler.postResumeSuggestions(true /* shouldIncludeResumedWordInSuggestions */, mHandler.postResumeSuggestions(false /* shouldDelay */);
false /* shouldDelay */);
} }
} }
@ -929,8 +923,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(true /* shouldIncludeResumedWordInSuggestions */, mHandler.postResumeSuggestions(true /* shouldDelay */);
true /* shouldDelay */);
needToCallLoadKeyboardLater = false; needToCallLoadKeyboardLater = false;
} }
} else { } else {

View File

@ -435,8 +435,7 @@ public final class InputLogic {
// removed. // removed.
mConnection.removeBackgroundColorFromHighlightedTextIfNecessary(); mConnection.removeBackgroundColorFromHighlightedTextIfNecessary();
// 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(false /* shouldIncludeResumedWordInSuggestions */, mLatinIME.mHandler.postResumeSuggestions(true /* shouldDelay */);
true /* shouldDelay */);
// Stop the last recapitalization, if started. // Stop the last recapitalization, if started.
mRecapitalizeStatus.stop(); mRecapitalizeStatus.stop();
return true; return true;
@ -1184,7 +1183,7 @@ public final class InputLogic {
&& !mConnection.isCursorFollowedByWordCharacter( && !mConnection.isCursorFollowedByWordCharacter(
inputTransaction.mSettingsValues.mSpacingAndPunctuations)) { inputTransaction.mSettingsValues.mSpacingAndPunctuations)) {
restartSuggestionsOnWordTouchedByCursor(inputTransaction.mSettingsValues, restartSuggestionsOnWordTouchedByCursor(inputTransaction.mSettingsValues,
true /* shouldIncludeResumedWordInSuggestions */, currentKeyboardScriptId); currentKeyboardScriptId);
} }
} }
} }
@ -1440,12 +1439,10 @@ 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 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 shouldIncludeResumedWordInSuggestions,
// TODO: remove this argument, put it into settingsValues // TODO: remove this argument, put it into settingsValues
final int currentKeyboardScriptId) { final int currentKeyboardScriptId) {
// 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
@ -1493,13 +1490,6 @@ 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 (shouldIncludeResumedWordInSuggestions) {
suggestions.add(new SuggestedWordInfo(typedWord,
SuggestedWords.MAX_SUGGESTIONS + 1,
SuggestedWordInfo.KIND_TYPED, Dictionary.DICTIONARY_USER_TYPED,
SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */,
SuggestedWordInfo.NOT_A_CONFIDENCE /* autoCommitFirstWordConfidence */));
}
if (!isResumableWord(settingsValues, typedWord)) { if (!isResumableWord(settingsValues, typedWord)) {
mSuggestionStripViewAccessor.setNeutralSuggestionStrip(); mSuggestionStripViewAccessor.setNeutralSuggestionStrip();
return; return;
@ -1532,7 +1522,7 @@ public final class InputLogic {
mConnection.maybeMoveTheCursorAroundAndRestoreToWorkaroundABug(); mConnection.maybeMoveTheCursorAroundAndRestoreToWorkaroundABug();
mConnection.setComposingRegion(expectedCursorPosition - numberOfCharsInWordBeforeCursor, mConnection.setComposingRegion(expectedCursorPosition - numberOfCharsInWordBeforeCursor,
expectedCursorPosition + range.getNumberOfCharsInWordAfterCursor()); expectedCursorPosition + range.getNumberOfCharsInWordAfterCursor());
if (suggestions.size() <= (shouldIncludeResumedWordInSuggestions ? 1 : 0)) { if (suggestions.size() <= 0) {
// If there weren't any suggestion spans on this word, suggestions#size() will be 1 // If there weren't any suggestion spans on this word, suggestions#size() will be 1
// if shouldIncludeResumedWordInSuggestions is true, 0 otherwise. In this case, we // if shouldIncludeResumedWordInSuggestions is true, 0 otherwise. In this case, we
// have no useful suggestions, so we will try to compute some for it instead. // have no useful suggestions, so we will try to compute some for it instead.
@ -1542,8 +1532,7 @@ public final class InputLogic {
public void onGetSuggestedWords( public void onGetSuggestedWords(
final SuggestedWords suggestedWordsIncludingTypedWord) { final SuggestedWords suggestedWordsIncludingTypedWord) {
final SuggestedWords suggestedWords; final SuggestedWords suggestedWords;
if (suggestedWordsIncludingTypedWord.size() > 1 if (suggestedWordsIncludingTypedWord.size() > 1) {
&& !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 #getSuggestedWordsExcludingTypedWordForRecorrection() // case. The #getSuggestedWordsExcludingTypedWordForRecorrection()
@ -2194,10 +2183,7 @@ public final class InputLogic {
} }
mConnection.tryFixLyingCursorPosition(); mConnection.tryFixLyingCursorPosition();
if (tryResumeSuggestions) { if (tryResumeSuggestions) {
// This is triggered when starting input anew, so we want to include the resumed handler.postResumeSuggestions(true /* shouldDelay */);
// word in suggestions.
handler.postResumeSuggestions(true /* shouldIncludeResumedWordInSuggestions */,
true /* shouldDelay */);
} }
return true; return true;
} }