diff --git a/changelog.d/3449.bugfix b/changelog.d/3449.bugfix new file mode 100644 index 0000000000..a4385fda2e --- /dev/null +++ b/changelog.d/3449.bugfix @@ -0,0 +1 @@ +Fixes left over text when inserting emojis via the ':' menu and replaces the last typed ':' rather than the one at the end of the message \ No newline at end of file diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/AutoCompleter.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/AutoCompleter.kt index 1d6530218d..7dbd8cc3b5 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/AutoCompleter.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/AutoCompleter.kt @@ -181,8 +181,8 @@ class AutoCompleter @AssistedInject constructor( .with(backgroundDrawable) .with(object : AutocompleteCallback { override fun onPopupItemClicked(editable: Editable, item: String): Boolean { - // Detect last ":" and remove it - var startIndex = editable.lastIndexOf(":") + // Infer that the last ":" before the current cursor position is the original popup trigger + var startIndex = editable.subSequence(0, editText.selectionStart).lastIndexOf(":") if (startIndex == -1) { startIndex = 0 } @@ -194,7 +194,8 @@ class AutoCompleter @AssistedInject constructor( } // Replace the word by its completion - editable.replace(startIndex, endIndex, item) + editable.delete(startIndex, endIndex) + editable.insert(startIndex, item) return true }