Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make setSelection safe #1062

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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