Merge "Improvement to tap detection for the delete button."
diff --git a/src/com/android/ex/chips/RecipientEditTextView.java b/src/com/android/ex/chips/RecipientEditTextView.java
index 4228c84..be4fe0d 100644
--- a/src/com/android/ex/chips/RecipientEditTextView.java
+++ b/src/com/android/ex/chips/RecipientEditTextView.java
@@ -385,18 +385,26 @@
             }
         }
 
-        // If the offset is beyond where there was any visible text,
-        // then leave it should not be pulled into the range of a chip.
-        if (offset > realLength) {
+        // If the offset is beyond or at the end of the text,
+        // leave it alone.
+        if (offset >= realLength) {
             return offset;
         }
-        while (offset >= 0 && findChip(offset) == null) {
+        Editable editable = getText();
+        while (offset >= 0 && (findText(editable, offset) == -1 && findChip(offset) == null)) {
             // Keep walking backward!
             offset--;
         }
         return offset;
     }
 
+    private int findText(Editable text, int offset) {
+        if (text.charAt(offset) != ' ') {
+            return offset;
+        }
+        return -1;
+    }
+
     private RecipientChip findChip(int offset) {
         RecipientChip[] chips = getSpannable().getSpans(0, offset, RecipientChip.class);
         // Find the chip that contains this offset.