Skip to content

Commit 11142e7

Browse files
authored
Merge pull request #613 from wordpress-mobile/issue/612-IndexOutOfBoundsException-paste-text
[Crash Report] Fix Cut & Paste IndexOutOfBoundsException
2 parents 1844004 + 4db70e2 commit 11142e7

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## [1.0.1](https://github.com/wordpress-mobile/AztecEditor-Android/releases/tag/v1.0.1) - 2018-01-22
4+
### Fixed
5+
- Crash when pasting certain text
6+
37
## [1.0](https://github.com/wordpress-mobile/AztecEditor-Android/releases/tag/v1.0) - 2018-01-11
48
### Fixed
59
- Various problems when editing captions

aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -886,13 +886,17 @@ class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknownHtmlT
886886
// Helper ======================================================================================
887887

888888
fun consumeCursorPosition(text: SpannableStringBuilder): Int {
889-
var cursorPosition = Math.min(selectionStart, length())
889+
var cursorPosition = Math.min(selectionStart, text.length)
890890

891891
text.getSpans(0, text.length, AztecCursorSpan::class.java).forEach {
892892
cursorPosition = text.getSpanStart(it)
893893
text.removeSpan(it)
894894
}
895895

896+
// Make sure the cursor position is a valid one
897+
cursorPosition = Math.min(cursorPosition, text.length)
898+
cursorPosition = Math.max(0, cursorPosition)
899+
896900
return cursorPosition
897901
}
898902

@@ -912,10 +916,12 @@ class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknownHtmlT
912916
it.textView = this
913917
}
914918

919+
val cursorPosition = consumeCursorPosition(builder)
920+
setSelection(0)
921+
915922
setTextKeepState(builder)
916923
enableTextChangedListener()
917924

918-
val cursorPosition = consumeCursorPosition(builder)
919925
setSelection(cursorPosition)
920926

921927
loadImages()

0 commit comments

Comments
 (0)