Skip to content

Commit d699110

Browse files
Victoria LeaseAndroid (Google) Code Review
authored andcommitted
Merge "Avert crash when dragging text in same TextView" into jb-mr1-dev
2 parents f9c6a10 + 9137320 commit d699110

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

core/java/android/widget/Editor.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1801,13 +1801,13 @@ void onDrop(DragEvent event) {
18011801
mTextView.deleteText_internal(dragSourceStart, dragSourceEnd);
18021802

18031803
// Make sure we do not leave two adjacent spaces.
1804-
CharSequence t = mTextView.getTransformedText(dragSourceStart - 1, dragSourceStart + 1);
1805-
if ( (dragSourceStart == 0 || Character.isSpaceChar(t.charAt(0))) &&
1806-
(dragSourceStart == mTextView.getText().length() ||
1807-
Character.isSpaceChar(t.charAt(1))) ) {
1808-
final int pos = dragSourceStart == mTextView.getText().length() ?
1809-
dragSourceStart - 1 : dragSourceStart;
1810-
mTextView.deleteText_internal(pos, pos + 1);
1804+
final int prevCharIdx = Math.max(0, dragSourceStart - 1);
1805+
final int nextCharIdx = Math.min(mTextView.getText().length(), dragSourceStart + 1);
1806+
if (nextCharIdx > prevCharIdx + 1) {
1807+
CharSequence t = mTextView.getTransformedText(prevCharIdx, nextCharIdx);
1808+
if (Character.isSpaceChar(t.charAt(0)) && Character.isSpaceChar(t.charAt(1))) {
1809+
mTextView.deleteText_internal(prevCharIdx, prevCharIdx + 1);
1810+
}
18111811
}
18121812
}
18131813
}

0 commit comments

Comments
 (0)