From 1bc97e0abafd7ca324ba8eaaa692e1bf98f80894 Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Wed, 2 Aug 2023 20:33:04 +0200 Subject: [PATCH] Fix possible crash in autocompletion https://github.com/SchildiChat/SchildiChat-android-rageshakes/issues/1129 Change-Id: If8514bdcd39e6477a938decf59d2380466898b23 --- .../app/features/home/room/detail/AutoCompleter.kt | 9 ++++++++- 1 file changed, 8 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 8b125d9ed6..49dcb3b724 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 @@ -305,7 +305,14 @@ class AutoCompleter @AssistedInject constructor( endIndex = editable.length } */ - val endIndex = editText.selectionEnd + var endIndex = editText.selectionEnd + if (endIndex == -1) { + endIndex = editable.length + } else if (endIndex < startIndex) { + val tmp = startIndex + startIndex = endIndex + endIndex = tmp + } // Replace the word by its completion val displayName = matrixItem.getBestName()