Make the delete tappable region even smaller.
Taps that are CLEARLY beyond the end of the visible text
should not cause a chip to get deleted.
Change-Id: I71d810c5a9969b0bba046a382c8c45755db35aa1
diff --git a/src/com/android/ex/chips/RecipientEditTextViewInner.java b/src/com/android/ex/chips/RecipientEditTextViewInner.java
index 3efadf0..e9a981e 100644
--- a/src/com/android/ex/chips/RecipientEditTextViewInner.java
+++ b/src/com/android/ex/chips/RecipientEditTextViewInner.java
@@ -352,6 +352,23 @@
// what comes before the finger.
private int putOffsetInRange(int o) {
int offset = o;
+ Editable text = getText();
+ int length = text.length();
+ // Remove whitespace from end to find "real end"
+ int realLength = length;
+ for (int i = length - 1; i >= 0; i--) {
+ if (text.charAt(i) == ' ') {
+ realLength--;
+ } else {
+ break;
+ }
+ }
+
+ // 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) {
+ return offset;
+ }
while (offset >= 0 && findChip(offset) == null) {
// Keep walking backward!
offset--;