Merge "[CB14.5] Stop copying WordComposers."
commit
35645ac39a
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue