When the user starts editing mid address and submit, always submit all the text.

Previously, when the user hit enter in the middle
of text they were editing, it would divide at the cursor and create
a chip to the left and leave text on the right. This fixes that issue.

Change-Id: If9fd92e4d07008e86351de85de0115d51aca204b
diff --git a/src/com/android/ex/chips/RecipientEditTextView.java b/src/com/android/ex/chips/RecipientEditTextView.java
index 8e0b789..fe9af95 100644
--- a/src/com/android/ex/chips/RecipientEditTextView.java
+++ b/src/com/android/ex/chips/RecipientEditTextView.java
@@ -519,10 +519,8 @@
                     if (mSelectedChip != null) {
                         clearSelectedChip();
                         return true;
-                    } else if (mSelectedChip == null) {
-                        if (focusNext()) {
-                            return true;
-                        }
+                    } else if (focusNext()) {
+                        return true;
                     }
                 }
                 break;
@@ -563,17 +561,28 @@
         boolean shouldSubmitAtPosition = false;
         int end = getSelectionEnd();
         int start = mTokenizer.findTokenStart(editable, end);
+        boolean submitText = false;
         if (enough) {
             RecipientChip[] chips = getSpannable().getSpans(start, end, RecipientChip.class);
             if ((chips == null || chips.length == 0)) {
                 // There's something being filtered or typed that has not been
                 // completed yet.
+                // Check for the end of the token.
+                end = mTokenizer.findTokenEnd(editable, start);
+                // The user has tapped somewhere in the middle of the text
+                // and started editing. In this case, we always want to
+                // submit the full text token and not what may be in the
+                // suggestions popup.
+                if (end != getSelectionEnd()) {
+                    submitText = true;
+                    setSelection(end);
+                }
                 shouldSubmitAtPosition = true;
             }
         }
 
         if (shouldSubmitAtPosition) {
-            if (getAdapter().getCount() > 0) {
+            if (!submitText && getAdapter().getCount() > 0) {
                 // choose the first entry.
                 submitItemAtPosition(0);
                 dismissDropDown();