From 72b67f65411cf07cb8cb2d52e859f46d9d5b91d4 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Wed, 5 Mar 2014 18:42:00 +0900 Subject: Rework the logic that tells if the cursor touches words Bug: 13312942 Change-Id: I6be6a558bbc6c88508150f9c25cadbd0240ff88e --- .../inputmethod/latin/RichInputConnection.java | 24 +++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'java/src') 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( -- cgit v1.2.3-83-g751a