From 6d4881176765841d07d84fbf9c8397c1fcbbd1cf Mon Sep 17 00:00:00 2001 From: Konrad Pozniak Date: Fri, 21 Feb 2020 22:08:41 +0100 Subject: [PATCH] fix crash when inserting custom emojis at the start of the compose field (#1706) --- .../tusky/components/compose/ComposeActivity.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/components/compose/ComposeActivity.kt b/app/src/main/java/com/keylesspalace/tusky/components/compose/ComposeActivity.kt index 43397d14..339bb3c5 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/compose/ComposeActivity.kt +++ b/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 val start = composeEditField.selectionStart.coerceAtMost(composeEditField.selectionEnd) val end = composeEditField.selectionStart.coerceAtLeast(composeEditField.selectionEnd) - val textToInsert = if ( - composeEditField.text.isNotEmpty() - && !composeEditField.text[start - 1].isWhitespace() - ) " $text" else text + val textToInsert = if (start > 0 && !composeEditField.text[start - 1].isWhitespace()) { + " $text" + } else { + text + } composeEditField.text.replace(start, end, textToInsert) // Set the cursor after the inserted text