Skip to content

Commit

Permalink
Make setSelection safe
Browse files Browse the repository at this point in the history
  • Loading branch information
planarvoid committed Oct 10, 2023
1 parent caf8f43 commit 75feb01
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2433,6 +2433,18 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
this.uncaughtExceptionHandler = null
}

override fun setSelection(index: Int) {
if (index in 0..this.length()) {
super.setSelection(index)
} else if (index < 0) {
AppLog.e(AppLog.T.EDITOR, "Attempted to set selection to incorrect value $index")
setSelection(0)
} else if (index > this.length()) {
AppLog.e(AppLog.T.EDITOR, "Attempted to set selection to incorrect value $index")
setSelection(this.length())
}
}

override fun dispatchHoverEvent(event: MotionEvent): Boolean {
return if (accessibilityDelegate.onHoverEvent(event)) true else super.dispatchHoverEvent(event)
}
Expand Down

0 comments on commit 75feb01

Please sign in to comment.