aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/RichInputConnection.java
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2014-03-05 18:42:00 +0900
committerJean Chalard <jchalard@google.com>2014-03-20 23:16:53 +0900
commit72b67f65411cf07cb8cb2d52e859f46d9d5b91d4 (patch)
treed5cb0f67576e73fb0ab77844d48885a5b042efbb /java/src/com/android/inputmethod/latin/RichInputConnection.java
parentc9498827f62449ebd040408f52ef01bd0bf3f07b (diff)
downloadlatinime-72b67f65411cf07cb8cb2d52e859f46d9d5b91d4.tar.gz
latinime-72b67f65411cf07cb8cb2d52e859f46d9d5b91d4.tar.xz
latinime-72b67f65411cf07cb8cb2d52e859f46d9d5b91d4.zip
Rework the logic that tells if the cursor touches words
Bug: 13312942 Change-Id: I6be6a558bbc6c88508150f9c25cadbd0240ff88e
Diffstat (limited to 'java/src/com/android/inputmethod/latin/RichInputConnection.java')
-rw-r--r--java/src/com/android/inputmethod/latin/RichInputConnection.java24
1 files changed, 17 insertions, 7 deletions
diff --git a/java/src/com/android/inputmethod/latin/RichInputConnection.java b/java/src/com/android/inputmethod/latin/RichInputConnection.java
index 965518e34..606bb775e 100644
--- a/java/src/com/android/inputmethod/latin/RichInputConnection.java
+++ b/java/src/com/android/inputmethod/latin/RichInputConnection.java
@@ -687,13 +687,23 @@ public final class RichInputConnection {
}
public boolean isCursorTouchingWord(final SpacingAndPunctuations spacingAndPunctuations) {
- final int codePointBeforeCursor = getCodePointBeforeCursor();
- if (Constants.NOT_A_CODE == codePointBeforeCursor
- || spacingAndPunctuations.isWordSeparator(codePointBeforeCursor)
- || spacingAndPunctuations.isWordConnector(codePointBeforeCursor)) {
- return isCursorFollowedByWordCharacter(spacingAndPunctuations);
- }
- return true;
+ if (isCursorFollowedByWordCharacter(spacingAndPunctuations)) {
+ // If what's after the cursor is a word character, then we're touching a word.
+ return true;
+ }
+ final String textBeforeCursor = mCommittedTextBeforeComposingText.toString();
+ int indexOfCodePointInJavaChars = textBeforeCursor.length();
+ int consideredCodePoint = 0 == indexOfCodePointInJavaChars ? Constants.NOT_A_CODE
+ : textBeforeCursor.codePointBefore(indexOfCodePointInJavaChars);
+ // Search for the first non word-connector char
+ if (spacingAndPunctuations.isWordConnector(consideredCodePoint)) {
+ indexOfCodePointInJavaChars -= Character.charCount(consideredCodePoint);
+ consideredCodePoint = 0 == indexOfCodePointInJavaChars ? Constants.NOT_A_CODE
+ : textBeforeCursor.codePointBefore(indexOfCodePointInJavaChars);
+ }
+ return !(Constants.NOT_A_CODE == consideredCodePoint
+ || spacingAndPunctuations.isWordSeparator(consideredCodePoint)
+ || spacingAndPunctuations.isWordConnector(consideredCodePoint));
}
public boolean isCursorFollowedByWordCharacter(