diff options
author | James Cook <jamescook@google.com> | 2015-03-10 09:48:11 -0700 |
---|---|---|
committer | James Cook <jamescook@google.com> | 2015-03-10 10:25:26 -0700 |
commit | 900185d00359661e185c3b328f40a4d572ae03f9 (patch) | |
tree | 79713b1eea9187b3429f2c8f54cded5e4429eb5d /core | |
parent | ba4df962972ee271e204d157aa785cb7d0b5d968 (diff) | |
download | frameworks_base-900185d00359661e185c3b328f40a4d572ae03f9.zip frameworks_base-900185d00359661e185c3b328f40a4d572ae03f9.tar.gz frameworks_base-900185d00359661e185c3b328f40a4d572ae03f9.tar.bz2 |
Handle undo in TextView fields with no cursor
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
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/widget/Editor.java | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java index 0f99e88..cc44577 100644 --- a/core/java/android/widget/Editor.java +++ b/core/java/android/widget/Editor.java @@ -4887,9 +4887,10 @@ public class Editor { 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); } } |