Merge "Bug 5428541: Check that span is still in text before deleting" into ics-mr0

This commit is contained in:
Gilles Debunne
2011-10-21 09:48:07 -07:00
committed by Android (Google) Code Review

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