Merge pull request #4566 from vector-im/feature/adm/typing-emoji-leftovers

Emoji insertion leftover characters
This commit is contained in:
Benoit Marty 2021-11-29 11:32:22 +01:00 committed by GitHub
commit 173ccc6bd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 3 deletions

1
changelog.d/3449.bugfix Normal file
View File

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

View File

@ -181,8 +181,8 @@ class AutoCompleter @AssistedInject constructor(
.with(backgroundDrawable) .with(backgroundDrawable)
.with(object : AutocompleteCallback<String> { .with(object : AutocompleteCallback<String> {
override fun onPopupItemClicked(editable: Editable, item: String): Boolean { override fun onPopupItemClicked(editable: Editable, item: String): Boolean {
// Detect last ":" and remove it // Infer that the last ":" before the current cursor position is the original popup trigger
var startIndex = editable.lastIndexOf(":") var startIndex = editable.subSequence(0, editText.selectionStart).lastIndexOf(":")
if (startIndex == -1) { if (startIndex == -1) {
startIndex = 0 startIndex = 0
} }
@ -194,7 +194,8 @@ class AutoCompleter @AssistedInject constructor(
} }
// Replace the word by its completion // Replace the word by its completion
editable.replace(startIndex, endIndex, item) editable.delete(startIndex, endIndex)
editable.insert(startIndex, item)
return true return true
} }