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
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 ) {