Restart suggestions when restarting input

Bug: 6851364
Change-Id: I3052924053f37f56c9c3953051aa1b22224a2b2e
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 1fdb8d1..607671a 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -816,9 +816,7 @@
             // When rotating, initialSelStart and initialSelEnd sometimes are lying. Make a best
             // effort to work around this bug.
             mInputLogic.mConnection.tryFixLyingCursorPosition();
-            if (isDifferentTextField) {
-                mHandler.postResumeSuggestions();
-            }
+            mHandler.postResumeSuggestions();
             canReachInputConnection = true;
         }
 
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
index 491d980..f1f9060 100644
--- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
+++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
@@ -1284,6 +1284,10 @@
                 || !settingsValues.mSpacingAndPunctuations.mCurrentLanguageHasSpaces
         // If no suggestions are requested, don't try restarting suggestions.
                 || !settingsValues.isSuggestionsRequested()
+        // If we are currently in a batch input, we must not resume suggestions, or the result
+        // of the batch input will replace the new composition. This may happen in the corner case
+        // that the app moves the cursor on its own accord during a batch input.
+                || mInputLogicHandler.isInBatchInput()
         // If the cursor is not touching a word, or if there is a selection, return right away.
                 || mConnection.hasSelection()
         // If we don't know the cursor location, return.
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogicHandler.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogicHandler.java
index 64bba68..9dbe2c3 100644
--- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogicHandler.java
+++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogicHandler.java
@@ -110,6 +110,10 @@
         }
     }
 
+    public boolean isInBatchInput() {
+        return mInBatchInput;
+    }
+
     /**
      * Fetch suggestions corresponding to an update of a batch input.
      * @param batchPointers the updated pointers, including the part that was passed last time.