diff options
author | 2014-03-20 14:35:19 +0000 | |
---|---|---|
committer | 2014-03-20 14:35:19 +0000 | |
commit | 1dda9107ca03fff08009eb865022ba707e174e15 (patch) | |
tree | 731c02be746c981f300d5118df1429dacc62c9a8 /java/src/com/android/inputmethod/latin/RichInputConnection.java | |
parent | 4df6bc0853fa5211416614130d1c027e6d0da210 (diff) | |
parent | 72b67f65411cf07cb8cb2d52e859f46d9d5b91d4 (diff) | |
download | latinime-1dda9107ca03fff08009eb865022ba707e174e15.tar.gz latinime-1dda9107ca03fff08009eb865022ba707e174e15.tar.xz latinime-1dda9107ca03fff08009eb865022ba707e174e15.zip |
Merge "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.java | 24 |
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( |