aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/RichInputConnection.java
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2013-06-24 06:09:54 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-06-24 06:09:55 +0000
commitc074c3357c3bb0dfe92fff90bccbcab2b6ec422e (patch)
tree8e98ee0410f1f928d15ea230b42583fc1a19c6dc /java/src/com/android/inputmethod/latin/RichInputConnection.java
parent80a4b7c92e96d359e0360f85b2ed3ed128ad0f3f (diff)
parente8c4b99e5665c6c19793df6c2490ee4bf281bf63 (diff)
downloadlatinime-c074c3357c3bb0dfe92fff90bccbcab2b6ec422e.tar.gz
latinime-c074c3357c3bb0dfe92fff90bccbcab2b6ec422e.tar.xz
latinime-c074c3357c3bb0dfe92fff90bccbcab2b6ec422e.zip
Merge "Refactor text range to be able to get spans larger than the word"
Diffstat (limited to 'java/src/com/android/inputmethod/latin/RichInputConnection.java')
-rw-r--r--java/src/com/android/inputmethod/latin/RichInputConnection.java43
1 files changed, 24 insertions, 19 deletions
diff --git a/java/src/com/android/inputmethod/latin/RichInputConnection.java b/java/src/com/android/inputmethod/latin/RichInputConnection.java
index 980215de6..4031e77bc 100644
--- a/java/src/com/android/inputmethod/latin/RichInputConnection.java
+++ b/java/src/com/android/inputmethod/latin/RichInputConnection.java
@@ -17,7 +17,6 @@
package com.android.inputmethod.latin;
import android.inputmethodservice.InputMethodService;
-import android.text.SpannableString;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
@@ -441,25 +440,33 @@ public final class RichInputConnection {
* Represents a range of text, relative to the current cursor position.
*/
public static final class Range {
- /** Characters before selection start */
- public final int mCharsBefore;
+ private final CharSequence mTextAtCursor;
+ private final int mWordAtCursorStartIndex;
+ private final int mWordAtCursorEndIndex;
+ private final int mCursorIndex;
- /**
- * Characters after selection start, including one trailing word
- * separator.
- */
- public final int mCharsAfter;
-
- /** The actual characters that make up a word */
public final CharSequence mWord;
- public Range(int charsBefore, int charsAfter, CharSequence word) {
- if (charsBefore < 0 || charsAfter < 0) {
+ public int getNumberOfCharsInWordBeforeCursor() {
+ return mCursorIndex - mWordAtCursorStartIndex;
+ }
+
+ public int getNumberOfCharsInWordAfterCursor() {
+ return mWordAtCursorEndIndex - mCursorIndex;
+ }
+
+ public Range(final CharSequence textAtCursor, final int wordAtCursorStartIndex,
+ final int wordAtCursorEndIndex, final int cursorIndex) {
+ if (wordAtCursorStartIndex < 0 || cursorIndex < wordAtCursorStartIndex
+ || cursorIndex > wordAtCursorEndIndex
+ || wordAtCursorEndIndex > textAtCursor.length()) {
throw new IndexOutOfBoundsException();
}
- this.mCharsBefore = charsBefore;
- this.mCharsAfter = charsAfter;
- this.mWord = word;
+ mTextAtCursor = textAtCursor;
+ mWordAtCursorStartIndex = wordAtCursorStartIndex;
+ mWordAtCursorEndIndex = wordAtCursorEndIndex;
+ mCursorIndex = cursorIndex;
+ mWord = mTextAtCursor.subSequence(mWordAtCursorStartIndex, mWordAtCursorEndIndex);
}
}
@@ -571,10 +578,8 @@ public final class RichInputConnection {
}
}
- final SpannableString word = new SpannableString(TextUtils.concat(
- before.subSequence(startIndexInBefore, before.length()),
- after.subSequence(0, endIndexInAfter)));
- return new Range(before.length() - startIndexInBefore, endIndexInAfter, word);
+ return new Range(TextUtils.concat(before, after), startIndexInBefore,
+ before.length() + endIndexInAfter, before.length());
}
public boolean isCursorTouchingWord(final SettingsValues settingsValues) {