am c5f7d74b: am 5db7eaba: Merge "Accept double-space-period after emoji."

* commit 'c5f7d74b2bb83e99bef7aad62924b0c043ce8961':
  Accept double-space-period after emoji.
main
Jean Chalard 2013-10-09 18:55:03 -07:00 committed by Android Git Automerger
commit 3ab42a00ec
2 changed files with 28 additions and 10 deletions

View File

@ -1438,11 +1438,21 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (!settingsValues.mCorrectionEnabled) return false; if (!settingsValues.mCorrectionEnabled) return false;
if (!settingsValues.mUseDoubleSpacePeriod) return false; if (!settingsValues.mUseDoubleSpacePeriod) return false;
if (!mHandler.isAcceptingDoubleSpacePeriod()) return false; if (!mHandler.isAcceptingDoubleSpacePeriod()) return false;
final CharSequence lastThree = mConnection.getTextBeforeCursor(3, 0); // We only do this when we see two spaces and an accepted code point before the cursor.
if (lastThree != null && lastThree.length() == 3 // The code point may be a surrogate pair but the two spaces may not, so we need 4 chars.
&& canBeFollowedByDoubleSpacePeriod(lastThree.charAt(0)) final CharSequence lastThree = mConnection.getTextBeforeCursor(4, 0);
&& lastThree.charAt(1) == Constants.CODE_SPACE if (null == lastThree) return false;
&& lastThree.charAt(2) == Constants.CODE_SPACE) { final int length = lastThree.length();
if (length < 3) return false;
if (lastThree.charAt(length - 1) != Constants.CODE_SPACE) return false;
if (lastThree.charAt(length - 2) != Constants.CODE_SPACE) return false;
// We know there are spaces in pos -1 and -2, and we have at least three chars.
// If we have only three chars, isSurrogatePairs can't return true as charAt(1) is a space,
// so this is fine.
final int firstCodePoint =
Character.isSurrogatePair(lastThree.charAt(0), lastThree.charAt(1)) ?
Character.codePointAt(lastThree, 0) : lastThree.charAt(length - 3);
if (canBeFollowedByDoubleSpacePeriod(firstCodePoint)) {
mHandler.cancelDoubleSpacePeriodTimer(); mHandler.cancelDoubleSpacePeriodTimer();
mConnection.deleteSurroundingText(2, 0); mConnection.deleteSurroundingText(2, 0);
final String textToInsert = ". "; final String textToInsert = ". ";
@ -1467,7 +1477,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|| codePoint == Constants.CODE_CLOSING_SQUARE_BRACKET || codePoint == Constants.CODE_CLOSING_SQUARE_BRACKET
|| codePoint == Constants.CODE_CLOSING_CURLY_BRACKET || codePoint == Constants.CODE_CLOSING_CURLY_BRACKET
|| codePoint == Constants.CODE_CLOSING_ANGLE_BRACKET || codePoint == Constants.CODE_CLOSING_ANGLE_BRACKET
|| codePoint == Constants.CODE_PLUS; || codePoint == Constants.CODE_PLUS
|| Character.getType(codePoint) == Character.OTHER_SYMBOL;
} }
// Callback for the {@link SuggestionStripView}, to call when the "add to dictionary" hint is // Callback for the {@link SuggestionStripView}, to call when the "add to dictionary" hint is

View File

@ -179,10 +179,17 @@ public class InputLogicTests extends InputTestsBase {
} }
public void testDoubleSpace() { public void testDoubleSpace() {
final String STRING_TO_TYPE = "this "; // U+1F607 is an emoji
final String EXPECTED_RESULT = "this. "; final String[] STRINGS_TO_TYPE =
type(STRING_TO_TYPE); new String[] { "this ", "a+ ", "\u1F607 ", ".. ", ") ", "( ", "% " };
assertEquals("double space make a period", EXPECTED_RESULT, mEditText.getText().toString()); final String[] EXPECTED_RESULTS =
new String[] { "this. ", "a+. ", "\u1F607. ", ".. ", "). ", "( ", "% " };
for (int i = 0; i < STRINGS_TO_TYPE.length; ++i) {
mEditText.setText("");
type(STRINGS_TO_TYPE[i]);
assertEquals("double space processing", EXPECTED_RESULTS[i],
mEditText.getText().toString());
}
} }
public void testCancelDoubleSpace() { public void testCancelDoubleSpace() {