aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/RichInputConnection.java
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2014-03-20 07:42:57 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2014-03-20 07:42:57 -0700
commit79213ea02c6a313ef9901f4871bbfb80a08c9459 (patch)
tree731c02be746c981f300d5118df1429dacc62c9a8 /java/src/com/android/inputmethod/latin/RichInputConnection.java
parent75ba24d4b333f8ea463e01ff1c7de1bacb5d6494 (diff)
parent1dda9107ca03fff08009eb865022ba707e174e15 (diff)
downloadlatinime-79213ea02c6a313ef9901f4871bbfb80a08c9459.tar.gz
latinime-79213ea02c6a313ef9901f4871bbfb80a08c9459.tar.xz
latinime-79213ea02c6a313ef9901f4871bbfb80a08c9459.zip
am 1dda9107: Merge "Rework the logic that tells if the cursor touches words"
* commit '1dda9107ca03fff08009eb865022ba707e174e15': Rework the logic that tells if the cursor touches words
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(