Skip to content

Commit 592ddaa

Browse files
author
Gilles Debunne
committed
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
1 parent 2159927 commit 592ddaa

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)