From 1da0b5be76b88baf2a6ae702f4ba8528feae8dda Mon Sep 17 00:00:00 2001 From: Valere Date: Thu, 23 May 2019 17:53:11 +0200 Subject: [PATCH] Fix / Block command completion in Quote and Edit mode --- .../autocomplete/command/CommandAutocompletePolicy.kt | 6 ++++-- .../features/home/room/detail/RoomDetailFragment.kt | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/vector/src/main/java/im/vector/riotredesign/features/autocomplete/command/CommandAutocompletePolicy.kt b/vector/src/main/java/im/vector/riotredesign/features/autocomplete/command/CommandAutocompletePolicy.kt index 74ee50aa..38556cdb 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/autocomplete/command/CommandAutocompletePolicy.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/autocomplete/command/CommandAutocompletePolicy.kt @@ -20,11 +20,13 @@ import android.text.Spannable import com.otaliastudios.autocomplete.AutocompletePolicy class CommandAutocompletePolicy : AutocompletePolicy { + + var enabled: Boolean = true + override fun getQuery(text: Spannable): CharSequence { if (text.length > 0) { return text.substring(1, text.length) } - // Should not happen return "" } @@ -34,7 +36,7 @@ class CommandAutocompletePolicy : AutocompletePolicy { // Only if text which starts with '/' and without space override fun shouldShowPopup(text: Spannable?, cursorPos: Int): Boolean { - return text?.startsWith("/") == true + return enabled && text?.startsWith("/") == true && !text.contains(" ") } diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailFragment.kt index e34e9762..89d76bf7 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailFragment.kt @@ -159,6 +159,7 @@ class RoomDetailFragment : private val roomDetailViewModel: RoomDetailViewModel by fragmentViewModel() private val textComposerViewModel: TextComposerViewModel by fragmentViewModel() private val timelineEventController: TimelineEventController by inject { parametersOf(this) } + private val commandAutocompletePolicy = CommandAutocompletePolicy() private val autocompleteCommandPresenter: AutocompleteCommandPresenter by inject { parametersOf(this) } private val autocompleteUserPresenter: AutocompleteUserPresenter by inject { parametersOf(this) } private val homePermalinkHandler: HomePermalinkHandler by inject() @@ -207,6 +208,7 @@ class RoomDetailFragment : RoomDetailViewState::roomId) { mode, event, roomId -> when (mode) { SendMode.REGULAR -> { + commandAutocompletePolicy.enabled = true val uid = session.sessionParams.credentials.userId val meMember = session.getRoom(roomId)?.getRoomMember(uid) AvatarRenderer.render(meMember?.avatarUrl, uid, meMember?.displayName, composer_avatar_view) @@ -216,6 +218,7 @@ class RoomDetailFragment : } SendMode.EDIT, SendMode.QUOTE -> { + commandAutocompletePolicy.enabled = false if (event == null) { //we should ignore? can this happen? Timber.e("Enter edit mode with no event selected") @@ -321,7 +324,7 @@ class RoomDetailFragment : val elevation = 6f val backgroundDrawable = ColorDrawable(Color.WHITE) Autocomplete.on(composerEditText) - .with(CommandAutocompletePolicy()) + .with(commandAutocompletePolicy) .with(autocompleteCommandPresenter) .with(elevation) .with(backgroundDrawable)