aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2013-10-04 13:05:43 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-10-04 13:05:43 +0000
commit5db7eabafb75a595403309b74c86cba5d4d5486f (patch)
treecf555db80b733e8601e7757517224eb3e172be7a /java/src
parent1d188a28fb0930217098fef10937674e24ca5a49 (diff)
parent8142fd83a6ed8dd6741579f724ebda9e2b70dd01 (diff)
downloadlatinime-5db7eabafb75a595403309b74c86cba5d4d5486f.tar.gz
latinime-5db7eabafb75a595403309b74c86cba5d4d5486f.tar.xz
latinime-5db7eabafb75a595403309b74c86cba5d4d5486f.zip
Merge "Accept double-space-period after emoji."
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java23
1 files changed, 17 insertions, 6 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 0f3d28976..21849ba14 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -1438,11 +1438,21 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (!settingsValues.mCorrectionEnabled) return false;
if (!settingsValues.mUseDoubleSpacePeriod) return false;
if (!mHandler.isAcceptingDoubleSpacePeriod()) return false;
- final CharSequence lastThree = mConnection.getTextBeforeCursor(3, 0);
- if (lastThree != null && lastThree.length() == 3
- && canBeFollowedByDoubleSpacePeriod(lastThree.charAt(0))
- && lastThree.charAt(1) == Constants.CODE_SPACE
- && lastThree.charAt(2) == Constants.CODE_SPACE) {
+ // We only do this when we see two spaces and an accepted code point before the cursor.
+ // The code point may be a surrogate pair but the two spaces may not, so we need 4 chars.
+ final CharSequence lastThree = mConnection.getTextBeforeCursor(4, 0);
+ if (null == lastThree) return false;
+ 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();
mConnection.deleteSurroundingText(2, 0);
final String textToInsert = ". ";
@@ -1467,7 +1477,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|| codePoint == Constants.CODE_CLOSING_SQUARE_BRACKET
|| codePoint == Constants.CODE_CLOSING_CURLY_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