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

main
Konrad Pozniak 4 years ago committed by GitHub
parent f699dbd8df
commit 316c7f202e
  1. 9
      app/src/main/java/com/keylesspalace/tusky/components/compose/ComposeActivity.kt

@ -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

Loading…
Cancel
Save