Skip to content

Commit 0499f90

Browse files
Gilles DebunneAndroid (Google) Code Review
authored andcommitted
Merge "Bug 5428541: Check that span is still in text before deleting" into ics-mr0
2 parents 4e7ce93 + 592ddaa commit 0499f90

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

core/java/android/widget/TextView.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9891,14 +9891,16 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
98919891
if (suggestionInfo.suggestionIndex == DELETE_TEXT) {
98929892
final int spanUnionStart = editable.getSpanStart(mSuggestionRangeSpan);
98939893
int spanUnionEnd = editable.getSpanEnd(mSuggestionRangeSpan);
9894-
// Do not leave two adjacent spaces after deletion, or one at beginning of text
9895-
if (spanUnionEnd < editable.length() &&
9896-
Character.isSpaceChar(editable.charAt(spanUnionEnd)) &&
9897-
(spanUnionStart == 0 ||
9898-
Character.isSpaceChar(editable.charAt(spanUnionStart - 1)))) {
9894+
if (spanUnionStart >= 0 && spanUnionEnd > spanUnionStart) {
9895+
// Do not leave two adjacent spaces after deletion, or one at beginning of text
9896+
if (spanUnionEnd < editable.length() &&
9897+
Character.isSpaceChar(editable.charAt(spanUnionEnd)) &&
9898+
(spanUnionStart == 0 ||
9899+
Character.isSpaceChar(editable.charAt(spanUnionStart - 1)))) {
98999900
spanUnionEnd = spanUnionEnd + 1;
9901+
}
9902+
editable.replace(spanUnionStart, spanUnionEnd, "");
99009903
}
9901-
editable.replace(spanUnionStart, spanUnionEnd, "");
99029904
hide();
99039905
return;
99049906
}

0 commit comments

Comments
 (0)