OSDN Git Service

Fix an exception in Contacts when you select text backwards from the end.
authorEric Fischer <enf@google.com>
Fri, 11 Sep 2009 00:57:45 +0000 (17:57 -0700)
committerEric Fischer <enf@google.com>
Fri, 11 Sep 2009 00:57:45 +0000 (17:57 -0700)
It was assuming that the end of the selection always came after or at the
start of the selection, and that therefore (start,end) was a safe range
to replace, but this is not actually the case when you select backwards --
in this case, the end comes before the start.

Bug 2087034

src/com/android/contacts/TwelveKeyDialer.java

index aa7cc70..0e9503a 100644 (file)
@@ -1011,8 +1011,11 @@ public class TwelveKeyDialer extends Activity implements View.OnClickListener,
         int selectionEnd;
 
         // SpannableStringBuilder editable_text = new SpannableStringBuilder(mDigits.getText());
-        selectionStart = mDigits.getSelectionStart();
-        selectionEnd = mDigits.getSelectionEnd();
+        int anchor = mDigits.getSelectionStart();
+        int point = mDigits.getSelectionEnd();
+
+        selectionStart = Math.min(anchor, point);
+        selectionEnd = Math.max(anchor, point);
 
         Editable digits = mDigits.getText();
         if (selectionStart != -1 ) {