fix crash when inserting custom emojis at the start of the compose field (#1706)

This commit is contained in:
Konrad Pozniak 2020-02-21 22:08:41 +01:00 committed by GitHub
parent 1eef035a9e
commit 6d48811767
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 4 deletions

View File

@ -412,10 +412,11 @@ class ComposeActivity : BaseActivity(),
// If you select "backward" in an editable, you get SelectionStart > SelectionEnd // If you select "backward" in an editable, you get SelectionStart > SelectionEnd
val start = composeEditField.selectionStart.coerceAtMost(composeEditField.selectionEnd) val start = composeEditField.selectionStart.coerceAtMost(composeEditField.selectionEnd)
val end = composeEditField.selectionStart.coerceAtLeast(composeEditField.selectionEnd) val end = composeEditField.selectionStart.coerceAtLeast(composeEditField.selectionEnd)
val textToInsert = if ( val textToInsert = if (start > 0 && !composeEditField.text[start - 1].isWhitespace()) {
composeEditField.text.isNotEmpty() " $text"
&& !composeEditField.text[start - 1].isWhitespace() } else {
) " $text" else text text
}
composeEditField.text.replace(start, end, textToInsert) composeEditField.text.replace(start, end, textToInsert)
// Set the cursor after the inserted text // Set the cursor after the inserted text