This fixes a rare crash in the undo system. In particular, if the
TextView did not have a cursor and the first operation was a
programmatic insert/append the "old cursor position" would be -1.
Attempting to undo would try to restore the cursor to -1 and crash.
Test will land separately in CTS.
Bug:
19332904
Change-Id: I9aa18c1e3621b99d13ac707e483154382effb81c
text.insert(newTextInsertAt, newText);
}
}
- // Restore the cursor position.
+ // Restore the cursor position. If there wasn't an old cursor (newCursorPos == -1) then
+ // don't explicitly set it and rely on SpannableStringBuilder to position it.
// TODO: Select all the text that was undone.
- if (newCursorPos <= text.length()) {
+ if (0 <= newCursorPos && newCursorPos <= text.length()) {
Selection.setSelection(text, newCursorPos);
}
}