Add shortcut for command length

This commit is contained in:
Benoit Marty 2019-12-04 20:12:55 +01:00
parent 57354cbd69
commit 411afb0bf3
3 changed files with 10 additions and 7 deletions

View file

@ -39,4 +39,7 @@ enum class Command(val command: String, val parameters: String, @StringRes val d
MARKDOWN("/markdown", "<on|off>", R.string.command_description_markdown),
CLEAR_SCALAR_TOKEN("/clear_scalar_token", "", R.string.command_description_clear_scalar_token),
SPOILER("/spoiler", "<message>", R.string.command_description_spoiler);
val length
get() = command.length + 1
}

View file

@ -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() }
)

View file

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