Merge "Fix: Selection created by long tap and drag can be empty."
diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java
index bf49048..cbac697 100644
--- a/core/java/android/widget/Editor.java
+++ b/core/java/android/widget/Editor.java
@@ -5477,10 +5477,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 ea22cd1..d0802a0 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());