From dffed4445d1ce95454d0ab462405502c0c893c9c Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Fri, 26 Nov 2021 11:57:47 +0000 Subject: [PATCH 1/4] fixing single character emoji searches retaining the original query - not entirely sure why this works but replacing the replace with separate delete + insert commands allows the previous query to be fully removed --- .../im/vector/app/features/home/room/detail/AutoCompleter.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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..4b12935f31 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 @@ -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 } From 20241f852a2fb26cfb88799ff21b8bd5a0044c64 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Fri, 26 Nov 2021 12:05:54 +0000 Subject: [PATCH 2/4] basing the emoji ':' search on the current edit text selection to avoid always replacing the last occurrence --- .../im/vector/app/features/home/room/detail/AutoCompleter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 4b12935f31..9c6478725b 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 @@ -182,7 +182,7 @@ class AutoCompleter @AssistedInject constructor( .with(object : AutocompleteCallback { override fun onPopupItemClicked(editable: Editable, item: String): Boolean { // Detect last ":" and remove it - var startIndex = editable.lastIndexOf(":") + var startIndex = editable.subSequence(0, editText.selectionStart).lastIndexOf(":") if (startIndex == -1) { startIndex = 0 } From cc9fb326dd93723aad672fff0160496b1acf58e9 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Fri, 26 Nov 2021 12:07:19 +0000 Subject: [PATCH 3/4] adding changelog entry --- changelog.d/3449.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/3449.bugfix 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 From 7b691cc43385d00446b689559352798577920b76 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Fri, 26 Nov 2021 16:21:57 +0000 Subject: [PATCH 4/4] updating comment to mention the cursor position --- .../im/vector/app/features/home/room/detail/AutoCompleter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 9c6478725b..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,7 +181,7 @@ class AutoCompleter @AssistedInject constructor( .with(backgroundDrawable) .with(object : AutocompleteCallback { 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.subSequence(0, editText.selectionStart).lastIndexOf(":") if (startIndex == -1) { startIndex = 0