aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/RichInputConnection.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin/RichInputConnection.java')
-rw-r--r--java/src/com/android/inputmethod/latin/RichInputConnection.java76
1 files changed, 38 insertions, 38 deletions
diff --git a/java/src/com/android/inputmethod/latin/RichInputConnection.java b/java/src/com/android/inputmethod/latin/RichInputConnection.java
index 79d66744b..325a0d981 100644
--- a/java/src/com/android/inputmethod/latin/RichInputConnection.java
+++ b/java/src/com/android/inputmethod/latin/RichInputConnection.java
@@ -27,7 +27,6 @@ import android.view.inputmethod.ExtractedTextRequest;
import android.view.inputmethod.InputConnection;
import com.android.inputmethod.latin.define.ProductionFlag;
-import com.android.inputmethod.latin.settings.SettingsValues;
import com.android.inputmethod.latin.settings.SpacingAndPunctuations;
import com.android.inputmethod.latin.utils.CapsModeUtils;
import com.android.inputmethod.latin.utils.DebugLogUtils;
@@ -36,6 +35,7 @@ import com.android.inputmethod.latin.utils.StringUtils;
import com.android.inputmethod.latin.utils.TextRange;
import com.android.inputmethod.research.ResearchLogger;
+import java.util.Arrays;
import java.util.regex.Pattern;
/**
@@ -98,7 +98,7 @@ public final class RichInputConnection {
final ExtractedText et = mIC.getExtractedText(r, 0);
final CharSequence beforeCursor = getTextBeforeCursor(Constants.EDITOR_CONTENTS_CACHE_SIZE,
0);
- final StringBuilder internal = new StringBuilder().append(mCommittedTextBeforeComposingText)
+ final StringBuilder internal = new StringBuilder(mCommittedTextBeforeComposingText)
.append(mComposingText);
if (null == et || null == beforeCursor) return;
final int actualLength = Math.min(beforeCursor.length(), internal.length());
@@ -253,8 +253,7 @@ public final class RichInputConnection {
}
public CharSequence getSelectedText(final int flags) {
- if (null == mIC) return null;
- return mIC.getSelectedText(flags);
+ return (null == mIC) ? null : mIC.getSelectedText(flags);
}
public boolean canDeleteCharacters() {
@@ -272,12 +271,12 @@ public final class RichInputConnection {
* American English, it's just the most common set of rules for English).
*
* @param inputType a mask of the caps modes to test for.
- * @param settingsValues the values of the settings to use for locale and separators.
+ * @param spacingAndPunctuations the values of the settings to use for locale and separators.
* @param hasSpaceBefore if we should consider there should be a space after the string.
* @return the caps modes that should be on as a set of bits
*/
- public int getCursorCapsMode(final int inputType, final SettingsValues settingsValues,
- final boolean hasSpaceBefore) {
+ public int getCursorCapsMode(final int inputType,
+ final SpacingAndPunctuations spacingAndPunctuations, final boolean hasSpaceBefore) {
mIC = mParent.getCurrentInputConnection();
if (null == mIC) return Constants.TextUtils.CAP_MODE_OFF;
if (!TextUtils.isEmpty(mComposingText)) {
@@ -304,13 +303,13 @@ public final class RichInputConnection {
// This never calls InputConnection#getCapsMode - in fact, it's a static method that
// never blocks or initiates IPC.
return CapsModeUtils.getCapsMode(mCommittedTextBeforeComposingText, inputType,
- settingsValues.mSpacingAndPunctuations, hasSpaceBefore);
+ spacingAndPunctuations, hasSpaceBefore);
}
public int getCodePointBeforeCursor() {
- if (mCommittedTextBeforeComposingText.length() < 1) return Constants.NOT_A_CODE;
- return Character.codePointBefore(mCommittedTextBeforeComposingText,
- mCommittedTextBeforeComposingText.length());
+ final int length = mCommittedTextBeforeComposingText.length();
+ if (length < 1) return Constants.NOT_A_CODE;
+ return Character.codePointBefore(mCommittedTextBeforeComposingText, length);
}
public CharSequence getTextBeforeCursor(final int n, final int flags) {
@@ -338,16 +337,12 @@ public final class RichInputConnection {
return s;
}
mIC = mParent.getCurrentInputConnection();
- if (null != mIC) {
- return mIC.getTextBeforeCursor(n, flags);
- }
- return null;
+ return (null == mIC) ? null : mIC.getTextBeforeCursor(n, flags);
}
public CharSequence getTextAfterCursor(final int n, final int flags) {
mIC = mParent.getCurrentInputConnection();
- if (null != mIC) return mIC.getTextAfterCursor(n, flags);
- return null;
+ return (null == mIC) ? null : mIC.getTextAfterCursor(n, flags);
}
public void deleteSurroundingText(final int beforeLength, final int afterLength) {
@@ -563,8 +558,8 @@ public final class RichInputConnection {
return getNthPreviousWord(prev, spacingAndPunctuations, n);
}
- private static boolean isSeparator(int code, String sep) {
- return sep.indexOf(code) != -1;
+ private static boolean isSeparator(final int code, final int[] sortedSeparators) {
+ return Arrays.binarySearch(sortedSeparators, code) >= 0;
}
// Get the nth word before cursor. n = 1 retrieves the word immediately before the cursor,
@@ -603,29 +598,29 @@ public final class RichInputConnection {
}
/**
- * @param separators characters which may separate words
+ * @param sortedSeparators a sorted array of code points which may separate words
* @return the word that surrounds the cursor, including up to one trailing
* separator. For example, if the field contains "he|llo world", where |
* represents the cursor, then "hello " will be returned.
*/
- public CharSequence getWordAtCursor(String separators) {
+ public CharSequence getWordAtCursor(final int[] sortedSeparators) {
// getWordRangeAtCursor returns null if the connection is null
- TextRange r = getWordRangeAtCursor(separators, 0);
+ final TextRange r = getWordRangeAtCursor(sortedSeparators, 0);
return (r == null) ? null : r.mWord;
}
/**
* Returns the text surrounding the cursor.
*
- * @param sep a string of characters that split words.
+ * @param sortedSeparators a sorted array of code points that split words.
* @param additionalPrecedingWordsCount the number of words before the current word that should
* be included in the returned range
* @return a range containing the text surrounding the cursor
*/
- public TextRange getWordRangeAtCursor(final String sep,
+ public TextRange getWordRangeAtCursor(final int[] sortedSeparators,
final int additionalPrecedingWordsCount) {
mIC = mParent.getCurrentInputConnection();
- if (mIC == null || sep == null) {
+ if (mIC == null) {
return null;
}
final CharSequence before = mIC.getTextBeforeCursor(Constants.EDITOR_CONTENTS_CACHE_SIZE,
@@ -644,7 +639,7 @@ public final class RichInputConnection {
while (true) { // see comments below for why this is guaranteed to halt
while (startIndexInBefore > 0) {
final int codePoint = Character.codePointBefore(before, startIndexInBefore);
- if (isStoppingAtWhitespace == isSeparator(codePoint, sep)) {
+ if (isStoppingAtWhitespace == isSeparator(codePoint, sortedSeparators)) {
break; // inner loop
}
--startIndexInBefore;
@@ -665,7 +660,7 @@ public final class RichInputConnection {
int endIndexInAfter = -1;
while (++endIndexInAfter < after.length()) {
final int codePoint = Character.codePointAt(after, endIndexInAfter);
- if (isSeparator(codePoint, sep)) {
+ if (isSeparator(codePoint, sortedSeparators)) {
break;
}
if (Character.isSupplementaryCodePoint(codePoint)) {
@@ -681,23 +676,28 @@ public final class RichInputConnection {
startIndexInBefore, before.length() + endIndexInAfter, before.length());
}
- public boolean isCursorTouchingWord(final SettingsValues settingsValues) {
+ public boolean isCursorTouchingWord(final SpacingAndPunctuations spacingAndPunctuations) {
final int codePointBeforeCursor = getCodePointBeforeCursor();
- if (Constants.NOT_A_CODE != codePointBeforeCursor
- && !settingsValues.isWordSeparator(codePointBeforeCursor)
- && !settingsValues.isWordConnector(codePointBeforeCursor)) {
- return true;
+ if (Constants.NOT_A_CODE == codePointBeforeCursor
+ || spacingAndPunctuations.isWordSeparator(codePointBeforeCursor)
+ || spacingAndPunctuations.isWordConnector(codePointBeforeCursor)) {
+ return isCursorFollowedByWordCharacter(spacingAndPunctuations);
}
- return isCursorFollowedByWordCharacter(settingsValues);
+ return true;
}
- public boolean isCursorFollowedByWordCharacter(final SettingsValues settingsValues) {
+ public boolean isCursorFollowedByWordCharacter(
+ final SpacingAndPunctuations spacingAndPunctuations) {
final CharSequence after = getTextAfterCursor(1, 0);
- if (!TextUtils.isEmpty(after) && !settingsValues.isWordSeparator(after.charAt(0))
- && !settingsValues.isWordConnector(after.charAt(0))) {
- return true;
+ if (TextUtils.isEmpty(after)) {
+ return false;
+ }
+ final int codePointAfterCursor = Character.codePointAt(after, 0);
+ if (spacingAndPunctuations.isWordSeparator(codePointAfterCursor)
+ || spacingAndPunctuations.isWordConnector(codePointAfterCursor)) {
+ return false;
}
- return false;
+ return true;
}
public void removeTrailingSpace() {