diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 47137e7fb9c331d2eabb9046fc297d83e5bf2ec9..16d5f5bb43a6079b00ff999fd8514da6cb045c2b 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -751,6 +751,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
                     + ", word caps = "
                     + ((editorInfo.inputType & InputType.TYPE_TEXT_FLAG_CAP_WORDS) != 0));
         }
+        Log.i(TAG, "Starting input. Cursor position = "
+                + editorInfo.initialSelStart + "," + editorInfo.initialSelEnd);
         if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
             final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
             ResearchLogger.latinIME_onStartInputViewInternal(editorInfo, prefs);
diff --git a/java/src/com/android/inputmethod/latin/RichInputConnection.java b/java/src/com/android/inputmethod/latin/RichInputConnection.java
index 0e85b3c77dca0a077ba02d42a3a8ef4c41c88f3c..30b20a335216ba567842fc9c0423467220379a84 100644
--- a/java/src/com/android/inputmethod/latin/RichInputConnection.java
+++ b/java/src/com/android/inputmethod/latin/RichInputConnection.java
@@ -847,9 +847,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