aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--java/src/com/android/inputmethod/latin/BinaryDictionary.java2
-rw-r--r--java/src/com/android/inputmethod/latin/Suggest.java15
-rw-r--r--java/src/com/android/inputmethod/latin/WordComposer.java26
-rw-r--r--tests/src/com/android/inputmethod/latin/InputLogicTests.java39
4 files changed, 48 insertions, 34 deletions
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
index 0aa34e82e..c986eb2ef 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
@@ -244,7 +244,7 @@ public final class BinaryDictionary extends Dictionary {
// TODO: toLowerCase in the native code
final int[] prevWordCodePointArray = (null == prevWord)
? null : StringUtils.toCodePointArray(prevWord);
- final int composerSize = composer.size();
+ final int composerSize = composer.sizeWithoutTrailingSingleQuotes();
final boolean isGesture = composer.isBatchMode();
if (composerSize <= 1 || !isGesture) {
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index 6985d9a84..db0a8a81c 100644
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -101,19 +101,6 @@ public final class Suggest {
: typedWord;
LatinImeLogger.onAddSuggestedWord(typedWord, Dictionary.TYPE_USER_TYPED);
- final WordComposer wordComposerForLookup;
- if (trailingSingleQuotesCount > 0) {
- wordComposerForLookup = new WordComposer(wordComposer);
- for (int i = trailingSingleQuotesCount - 1; i >= 0; --i) {
- // TODO: do not create a fake event for this. Ideally the word composer should know
- // how to give out the word without trailing quotes and we can remove this entirely
- wordComposerForLookup.deleteLast(Event.createSoftwareKeypressEvent(
- Event.NOT_A_CODE_POINT, Constants.CODE_DELETE,
- Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE));
- }
- } else {
- wordComposerForLookup = wordComposer;
- }
final ArrayList<SuggestedWordInfo> rawSuggestions;
if (ProductionFlag.INCLUDE_RAW_SUGGESTIONS) {
rawSuggestions = CollectionUtils.newArrayList();
@@ -121,7 +108,7 @@ public final class Suggest {
rawSuggestions = null;
}
final SuggestionResults suggestionResults = mDictionaryFacilitator.getSuggestionResults(
- wordComposerForLookup, prevWordForBigram, proximityInfo, blockOffensiveWords,
+ wordComposer, prevWordForBigram, proximityInfo, blockOffensiveWords,
additionalFeaturesOptions, SESSION_TYPING, rawSuggestions);
final boolean isFirstCharCapitalized = wordComposer.isFirstCharCapitalized();
diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java
index a955f375b..324683c86 100644
--- a/java/src/com/android/inputmethod/latin/WordComposer.java
+++ b/java/src/com/android/inputmethod/latin/WordComposer.java
@@ -104,25 +104,6 @@ public final class WordComposer {
refreshSize();
}
- public WordComposer(final WordComposer source) {
- mCombinerChain = source.mCombinerChain;
- mPrimaryKeyCodes = Arrays.copyOf(source.mPrimaryKeyCodes, source.mPrimaryKeyCodes.length);
- mEvents = new ArrayList<Event>(source.mEvents);
- mTypedWord = new StringBuilder(source.mTypedWord);
- mInputPointers.copy(source.mInputPointers);
- mCapsCount = source.mCapsCount;
- mDigitsCount = source.mDigitsCount;
- mIsFirstCharCapitalized = source.mIsFirstCharCapitalized;
- mCapitalizedMode = source.mCapitalizedMode;
- mTrailingSingleQuotesCount = source.mTrailingSingleQuotesCount;
- mIsResumed = source.mIsResumed;
- mIsBatchMode = source.mIsBatchMode;
- mCursorPositionWithinWord = source.mCursorPositionWithinWord;
- mRejectedBatchModeSuggestion = source.mRejectedBatchModeSuggestion;
- mPreviousWordForSuggestion = source.mPreviousWordForSuggestion;
- refreshSize();
- }
-
/**
* Clear out the keys registered so far.
*/
@@ -155,6 +136,13 @@ public final class WordComposer {
return mCodePointSize;
}
+ // When the composition contains trailing quotes, we don't pass them to the suggestion engine.
+ // This is because "'tgis'" should be corrected to "'this'", but we can't afford to consider
+ // single quotes as separators because of their very common use as apostrophes.
+ public int sizeWithoutTrailingSingleQuotes() {
+ return size() - mTrailingSingleQuotesCount;
+ }
+
public final boolean isComposingWord() {
return size() > 0;
}
diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTests.java b/tests/src/com/android/inputmethod/latin/InputLogicTests.java
index d4e6ad87a..b36645289 100644
--- a/tests/src/com/android/inputmethod/latin/InputLogicTests.java
+++ b/tests/src/com/android/inputmethod/latin/InputLogicTests.java
@@ -474,4 +474,43 @@ public class InputLogicTests extends InputTestsBase {
WORD_TO_TYPE.length() * TIMES_TO_TYPE - TIMES_TO_BACKSPACE,
mEditText.getText().length());
}
+
+ public void testManySingleQuotes() {
+ final String WORD_TO_AUTOCORRECT = "i";
+ final String WORD_AUTOCORRECTED = "I";
+ final String QUOTES = "''''''''''''''''''''";
+ final String WORD_TO_TYPE = WORD_TO_AUTOCORRECT + QUOTES + " ";
+ final String EXPECTED_RESULT = WORD_AUTOCORRECTED + QUOTES + " ";
+ type(WORD_TO_TYPE);
+ assertEquals("auto-correct with many trailing single quotes", EXPECTED_RESULT,
+ mEditText.getText().toString());
+ }
+
+ public void testManySingleQuotesOneByOne() {
+ final String WORD_TO_AUTOCORRECT = "i";
+ final String WORD_AUTOCORRECTED = "I";
+ final String QUOTES = "''''''''''''''''''''";
+ final String WORD_TO_TYPE = WORD_TO_AUTOCORRECT + QUOTES + " ";
+ final String EXPECTED_RESULT = WORD_AUTOCORRECTED + QUOTES + " ";
+
+ for (int i = 0; i < WORD_TO_TYPE.length(); ++i) {
+ type(WORD_TO_TYPE.substring(i, i+1));
+ sleep(DELAY_TO_WAIT_FOR_PREDICTIONS);
+ runMessages();
+ }
+ assertEquals("type many trailing single quotes one by one", EXPECTED_RESULT,
+ mEditText.getText().toString());
+ }
+
+ public void testTypingSingleQuotesOneByOne() {
+ final String WORD_TO_TYPE = "it's ";
+ final String EXPECTED_RESULT = WORD_TO_TYPE;
+ for (int i = 0; i < WORD_TO_TYPE.length(); ++i) {
+ type(WORD_TO_TYPE.substring(i, i+1));
+ sleep(DELAY_TO_WAIT_FOR_PREDICTIONS);
+ runMessages();
+ }
+ assertEquals("type words letter by letter", EXPECTED_RESULT,
+ mEditText.getText().toString());
+ }
}