From 358e1327d8d1c392ab711778d8e616400360e313 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Wed, 31 Aug 2011 20:49:45 +0900 Subject: [PATCH] Fix a bug where autotext would occasionally not work Autotext correction would check whether the first suggestion so far was the same as what Autotext would return, and if it was indeed the same, would not send its result as autocorrect. However, the first suggestion is not guaranteed to have a high enough score to trigger autocorrection, and there would be cases where a word in autotext would not get autocorrected because the word came out of bigram suggestions. These occurrences would be extremely rare, as they would require concomitant insert between autotext for one char and bigram suggestion. It is, in fact, probably limited to the capitalization of "I". This did not happen in gingerbread because gingerbread would not register 1-letter words as valid bigrams. This fix works by just always sending the result of autotext regardless of whether it is already the first suggestion or not. This is okay because duplicates are removed afterwards anyway - and this processing is absolutely necessary because the autotext'd word may actually be somewhere else in the suggestion, so it made really no sense checking for only the first one. Please note that there is also a race condition that can result in "i" not being converted to "I": at the moment, Latin IME relies on having the suggestions evaluated at the time autocorrection is performed, but when typing very, very fast, those messages may have been canceled. This is not limited to the autocorrection of "i", but affects all autocorrections. It requires a nearly inhumane typing speed to trigger, but hitting "i" and space in turn as fast as one can it's possible to reproduce occasionally. Bug: 5135113 Change-Id: I530ea6212487300001a2c0fc5b25a5c7716bdf63 --- .../android/inputmethod/latin/Suggest.java | 20 +++++-------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 29b629576..93933f1bc 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -371,24 +371,14 @@ public class Suggest implements Dictionary.WordCallback { // Apply quick fix only for the typed word. if (mQuickFixesEnabled) { final String lowerCaseTypedWord = typedWordString.toLowerCase(); - CharSequence tempAutoText = capitalizeWord( - mIsAllUpperCase, mIsFirstCharCapitalized, AutoText.get( - lowerCaseTypedWord, 0, lowerCaseTypedWord.length(), view)); - // TODO: cleanup canAdd // Is there an AutoText (also known as Quick Fixes) correction? // Capitalize as needed - boolean canAdd = tempAutoText != null; - // Is that correction already the current prediction (or original word)? - canAdd &= !TextUtils.equals(tempAutoText, typedWord); - // Is that correction already the next predicted word? - if (canAdd && mSuggestions.size() > 0 && mCorrectionMode != CORRECTION_BASIC) { - canAdd &= !TextUtils.equals(tempAutoText, mSuggestions.get(0)); - } - if (canAdd) { - if (DBG) { - Log.d(TAG, "Auto corrected by AUTOTEXT."); + autoText = capitalizeWord(mIsAllUpperCase, mIsFirstCharCapitalized, AutoText.get( + lowerCaseTypedWord, 0, lowerCaseTypedWord.length(), view)); + if (DBG) { + if (autoText != null) { + Log.d(TAG, "Auto corrected by AUTOTEXT: " + typedWord + " -> " + autoText); } - autoText = tempAutoText; } } }