diff --git a/vector/src/main/java/im/vector/riotx/features/command/Command.kt b/vector/src/main/java/im/vector/riotx/features/command/Command.kt index 9b3ecb3be5..8b72ffa4a6 100644 --- a/vector/src/main/java/im/vector/riotx/features/command/Command.kt +++ b/vector/src/main/java/im/vector/riotx/features/command/Command.kt @@ -39,4 +39,7 @@ enum class Command(val command: String, val parameters: String, @StringRes val d MARKDOWN("/markdown", "", R.string.command_description_markdown), CLEAR_SCALAR_TOKEN("/clear_scalar_token", "", R.string.command_description_clear_scalar_token), SPOILER("/spoiler", "", R.string.command_description_spoiler); + + val length + get() = command.length + 1 } diff --git a/vector/src/main/java/im/vector/riotx/features/command/CommandParser.kt b/vector/src/main/java/im/vector/riotx/features/command/CommandParser.kt index bdcaa4d9b8..359f2c1f13 100644 --- a/vector/src/main/java/im/vector/riotx/features/command/CommandParser.kt +++ b/vector/src/main/java/im/vector/riotx/features/command/CommandParser.kt @@ -87,7 +87,7 @@ object CommandParser { if (roomAlias.isNotEmpty()) { ParsedCommand.JoinRoom( roomAlias, - textMessage.substring(Command.JOIN_ROOM.command.length + 1 + roomAlias.length) + textMessage.substring(Command.JOIN_ROOM.length + roomAlias.length) .trim() .takeIf { it.isNotBlank() } ) @@ -105,7 +105,7 @@ object CommandParser { if (roomAlias.isNotEmpty()) { ParsedCommand.PartRoom( roomAlias, - textMessage.substring(Command.PART.command.length + 1 + roomAlias.length) + textMessage.substring(Command.PART.length + roomAlias.length) .trim() .takeIf { it.isNotBlank() } ) @@ -123,7 +123,7 @@ object CommandParser { if (MatrixPatterns.isUserId(userId)) { ParsedCommand.Invite( userId, - textMessage.substring(Command.INVITE.command.length + 1 + userId.length) + textMessage.substring(Command.INVITE.length + userId.length) .trim() .takeIf { it.isNotBlank() } ) @@ -141,7 +141,7 @@ object CommandParser { if (MatrixPatterns.isUserId(userId)) { ParsedCommand.KickUser( userId, - textMessage.substring(Command.KICK_USER.command.length + 1 + userId.length) + textMessage.substring(Command.KICK_USER.length + userId.length) .trim() .takeIf { it.isNotBlank() } ) @@ -159,7 +159,7 @@ object CommandParser { if (MatrixPatterns.isUserId(userId)) { ParsedCommand.BanUser( userId, - textMessage.substring(Command.BAN_USER.command.length + 1 + userId.length) + textMessage.substring(Command.BAN_USER.length + userId.length) .trim() .takeIf { it.isNotBlank() } ) @@ -177,7 +177,7 @@ object CommandParser { if (MatrixPatterns.isUserId(userId)) { ParsedCommand.UnbanUser( userId, - textMessage.substring(Command.UNBAN_USER.command.length + 1 + userId.length) + textMessage.substring(Command.UNBAN_USER.length + userId.length) .trim() .takeIf { it.isNotBlank() } ) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt index d50b0c9f68..19ba1a85ce 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt @@ -1181,7 +1181,7 @@ class RoomDetailFragment @Inject constructor( && userId == session.myUserId) { // Empty composer, current user: start an emote composerLayout.composerEditText.setText(Command.EMOTE.command + " ") - composerLayout.composerEditText.setSelection(Command.EMOTE.command.length + 1) + composerLayout.composerEditText.setSelection(Command.EMOTE.length) } else { val roomMember = roomDetailViewModel.getMember(userId) // TODO move logic outside of fragment