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.java28
1 files changed, 9 insertions, 19 deletions
diff --git a/java/src/com/android/inputmethod/latin/RichInputConnection.java b/java/src/com/android/inputmethod/latin/RichInputConnection.java
index cc2db4c93..323256d1c 100644
--- a/java/src/com/android/inputmethod/latin/RichInputConnection.java
+++ b/java/src/com/android/inputmethod/latin/RichInputConnection.java
@@ -172,20 +172,6 @@ public final class RichInputConnection {
Log.d(TAG, "Will try to retrieve text later.");
return false;
}
- final int lengthOfTextBeforeCursor = mCommittedTextBeforeComposingText.length();
- if (lengthOfTextBeforeCursor > newSelStart
- || (newSelStart != lengthOfTextBeforeCursor
- && lengthOfTextBeforeCursor < Constants.EDITOR_CONTENTS_CACHE_SIZE
- && newSelStart < Constants.EDITOR_CONTENTS_CACHE_SIZE)) {
- // newSelStart and newSelEnd may be lying -- when rotating the device (probably a
- // framework bug). If the values don't agree and we have less chars than we asked
- // for, then we know how many chars we have. If we got more than newSelStart says, then
- // we also know it was lying. In both cases the length is more reliable. Note that we
- // only have to check newSelStart (not newSelEnd) since if newSelEnd is wrong, then
- // newSelStart will be wrong as well.
- mExpectedSelStart = lengthOfTextBeforeCursor;
- mExpectedSelEnd = lengthOfTextBeforeCursor;
- }
if (null != mIC && shouldFinishComposition) {
mIC.finishComposingText();
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
@@ -497,12 +483,16 @@ public final class RichInputConnection {
*
* @param start the character index where the selection should start.
* @param end the character index where the selection should end.
- * @return Returns true on success, false if the input connection is no longer valid either when
- * setting the selection or when retrieving the text cache at that point.
+ * @return Returns true on success, false on failure: either the input connection is no longer
+ * valid when setting the selection or when retrieving the text cache at that point, or
+ * invalid arguments were passed.
*/
public boolean setSelection(final int start, final int end) {
if (DEBUG_BATCH_NESTING) checkBatchEdit();
if (DEBUG_PREVIOUS_TEXT) checkConsistencyForDebug();
+ if (start < 0 || end < 0) {
+ return false;
+ }
mExpectedSelStart = start;
mExpectedSelEnd = end;
if (null != mIC) {
@@ -861,9 +851,9 @@ public final class RichInputConnection {
mExpectedSelStart = mExpectedSelEnd = Constants.NOT_A_CURSOR_POSITION;
} else {
final int textLength = textBeforeCursor.length();
- if (textLength > mExpectedSelStart
- || (textLength < Constants.EDITOR_CONTENTS_CACHE_SIZE
- && mExpectedSelStart < Constants.EDITOR_CONTENTS_CACHE_SIZE)) {
+ if (textLength < Constants.EDITOR_CONTENTS_CACHE_SIZE
+ && (textLength > mExpectedSelStart
+ || mExpectedSelStart < Constants.EDITOR_CONTENTS_CACHE_SIZE)) {
// It should not be possible to have only one of those variables be
// NOT_A_CURSOR_POSITION, so if they are equal, either the selection is zero-sized
// (simple cursor, no selection) or there is no cursor/we don't know its pos