OSDN Git Service

Merge "Fix crash due to reverse selection." into mnc-dev
[android-x86/frameworks-base.git] / core / java / android / widget / TextView.java
index c2f32dd..7b58b5b 100644 (file)
@@ -7577,10 +7577,14 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
     }
 
     String getSelectedText() {
-        if (hasSelection()) {
-            return String.valueOf(mText.subSequence(getSelectionStart(), getSelectionEnd()));
+        if (!hasSelection()) {
+            return null;
         }
-        return null;
+
+        final int start = getSelectionStart();
+        final int end = getSelectionEnd();
+        return String.valueOf(
+                start > end ? mText.subSequence(end, start) : mText.subSequence(start, end));
     }
 
     /**