Fix: Selection created by long tap and drag can be empty.
Bug: 21302473
Change-Id: Ia81729a402957d25b40d203af3ce69c166f8dc91
diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java
index e0a81dd..d8a013b 100644
--- a/core/java/android/widget/Editor.java
+++ b/core/java/android/widget/Editor.java
@@ -5403,10 +5403,12 @@
// Expanding with start handle.
offset = getWordStart(offset);
startOffset = getWordEnd(mStartOffset);
+ if (startOffset == offset) {
+ offset = getNextCursorOffset(offset, false);
+ }
}
mLineSelectionIsOn = currLine;
- Selection.setSelection((Spannable) mTextView.getText(),
- startOffset, offset);
+ Selection.setSelection((Spannable) mTextView.getText(), startOffset, offset);
}
private void updateParagraphBasedSelection(MotionEvent event) {
diff --git a/core/tests/coretests/src/android/widget/TextViewActivityTest.java b/core/tests/coretests/src/android/widget/TextViewActivityTest.java
index 1ea3534..01d01a2 100644
--- a/core/tests/coretests/src/android/widget/TextViewActivityTest.java
+++ b/core/tests/coretests/src/android/widget/TextViewActivityTest.java
@@ -170,6 +170,21 @@
}
@SmallTest
+ public void testLongPressAndDragToSelect_emoji() throws Exception {
+ final String text = "\uD83D\uDE00\uD83D\uDE01\uD83D\uDE02\uD83D\uDE03";
+ onView(withId(R.id.textview)).perform(click());
+ onView(withId(R.id.textview)).perform(replaceText(text));
+
+ onView(withId(R.id.textview)).perform(longPressAndDragOnText(4, 6));
+ onView(withId(R.id.textview)).check(hasSelection("\uD83D\uDE02"));
+
+ onView(withId(R.id.textview)).perform(click());
+
+ onView(withId(R.id.textview)).perform(longPressAndDragOnText(4, 2));
+ onView(withId(R.id.textview)).check(hasSelection("\uD83D\uDE01"));
+ }
+
+ @SmallTest
public void testDragAndDrop() throws Exception {
final String text = "abc def ghi.";
onView(withId(R.id.textview)).perform(click());