Latin IME bug with deleted text will reappear after screen orientation changes

The deleted text should not appear after screen orientation changes.
When change screen orientation, if the text in editText doesn't contain typedWord, reset mWordCompser.

The cases are as follows:
1. Enter a word that is not in the dictionary to a editText, and enter space
2. Select this word and delete it through the pop-up window
3. Change the screen orientation

Bug: 74163611
Change-Id: I25b2937921851c7dffbcc66216fea52e8c404824
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
index a7804a1..b8c21cf 100644
--- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
+++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
@@ -189,10 +189,22 @@
         // the useless IPC of {begin,end}BatchEdit.
         if (mWordComposer.isComposingWord()) {
             mConnection.beginBatchEdit();
+
+            final CharSequence textBeforeCursor =
+                    mConnection.getTextBeforeCursor(Constants.EDITOR_CONTENTS_CACHE_SIZE, 0);
+            final CharSequence textAfterCursor =
+                    mConnection.getTextAfterCursor(Constants.EDITOR_CONTENTS_CACHE_SIZE, 0);
+            final String text = String.valueOf(textBeforeCursor) + String.valueOf(textAfterCursor);
+            final String typedWord = mWordComposer.getTypedWord();
+            if (textBeforeCursor != null && !text.contains(typedWord)) {
+                mWordComposer.reset();
+            }
+
             // If we had a composition in progress, we need to commit the word so that the
             // suggestionsSpan will be added. This will allow resuming on the same suggestions
             // after rotation is finished.
             commitTyped(settingsValues, LastComposedWord.NOT_A_SEPARATOR);
+            mConnection.finishComposingText();
             mConnection.endBatchEdit();
         }
     }