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
This commit is contained in:
Gilles Debunne
2011-10-11 16:01:22 -07:00
parent 2159927f36
commit 592ddaa34f

View File

@@ -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;
}