From 592ddaa34f5a6799e4bb707996a3b8308448282e Mon Sep 17 00:00:00 2001 From: Gilles Debunne Date: Tue, 11 Oct 2011 16:01:22 -0700 Subject: [PATCH] Bug 5428541: Check that span is still in text before deleting This is a cherry-pick in MR0 of CL 141388 from master. Bug 5488537 In case the span has been removed from the text since the popup was showed, the delete action is a no-op. Change-Id: Iec2aeaf03becd82ad44715d5c08bfaa8f62aa3fe --- core/java/android/widget/TextView.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index a21a087ef6722..7f03adfbdeabc 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -9891,14 +9891,16 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener if (suggestionInfo.suggestionIndex == DELETE_TEXT) { final int spanUnionStart = editable.getSpanStart(mSuggestionRangeSpan); int spanUnionEnd = editable.getSpanEnd(mSuggestionRangeSpan); - // Do not leave two adjacent spaces after deletion, or one at beginning of text - if (spanUnionEnd < editable.length() && - Character.isSpaceChar(editable.charAt(spanUnionEnd)) && - (spanUnionStart == 0 || - Character.isSpaceChar(editable.charAt(spanUnionStart - 1)))) { + if (spanUnionStart >= 0 && spanUnionEnd > spanUnionStart) { + // Do not leave two adjacent spaces after deletion, or one at beginning of text + if (spanUnionEnd < editable.length() && + Character.isSpaceChar(editable.charAt(spanUnionEnd)) && + (spanUnionStart == 0 || + Character.isSpaceChar(editable.charAt(spanUnionStart - 1)))) { spanUnionEnd = spanUnionEnd + 1; + } + editable.replace(spanUnionStart, spanUnionEnd, ""); } - editable.replace(spanUnionStart, spanUnionEnd, ""); hide(); return; }