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), MARKDOWN("/markdown", "<on|off>", R.string.command_description_markdown),
CLEAR_SCALAR_TOKEN("/clear_scalar_token", "", R.string.command_description_clear_scalar_token), CLEAR_SCALAR_TOKEN("/clear_scalar_token", "", R.string.command_description_clear_scalar_token),
SPOILER("/spoiler", "<message>", R.string.command_description_spoiler); 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()) { if (roomAlias.isNotEmpty()) {
ParsedCommand.JoinRoom( ParsedCommand.JoinRoom(
roomAlias, roomAlias,
textMessage.substring(Command.JOIN_ROOM.command.length + 1 + roomAlias.length) textMessage.substring(Command.JOIN_ROOM.length + roomAlias.length)
.trim() .trim()
.takeIf { it.isNotBlank() } .takeIf { it.isNotBlank() }
) )
@ -105,7 +105,7 @@ object CommandParser {
if (roomAlias.isNotEmpty()) { if (roomAlias.isNotEmpty()) {
ParsedCommand.PartRoom( ParsedCommand.PartRoom(
roomAlias, roomAlias,
textMessage.substring(Command.PART.command.length + 1 + roomAlias.length) textMessage.substring(Command.PART.length + roomAlias.length)
.trim() .trim()
.takeIf { it.isNotBlank() } .takeIf { it.isNotBlank() }
) )
@ -123,7 +123,7 @@ object CommandParser {
if (MatrixPatterns.isUserId(userId)) { if (MatrixPatterns.isUserId(userId)) {
ParsedCommand.Invite( ParsedCommand.Invite(
userId, userId,
textMessage.substring(Command.INVITE.command.length + 1 + userId.length) textMessage.substring(Command.INVITE.length + userId.length)
.trim() .trim()
.takeIf { it.isNotBlank() } .takeIf { it.isNotBlank() }
) )
@ -141,7 +141,7 @@ object CommandParser {
if (MatrixPatterns.isUserId(userId)) { if (MatrixPatterns.isUserId(userId)) {
ParsedCommand.KickUser( ParsedCommand.KickUser(
userId, userId,
textMessage.substring(Command.KICK_USER.command.length + 1 + userId.length) textMessage.substring(Command.KICK_USER.length + userId.length)
.trim() .trim()
.takeIf { it.isNotBlank() } .takeIf { it.isNotBlank() }
) )
@ -159,7 +159,7 @@ object CommandParser {
if (MatrixPatterns.isUserId(userId)) { if (MatrixPatterns.isUserId(userId)) {
ParsedCommand.BanUser( ParsedCommand.BanUser(
userId, userId,
textMessage.substring(Command.BAN_USER.command.length + 1 + userId.length) textMessage.substring(Command.BAN_USER.length + userId.length)
.trim() .trim()
.takeIf { it.isNotBlank() } .takeIf { it.isNotBlank() }
) )
@ -177,7 +177,7 @@ object CommandParser {
if (MatrixPatterns.isUserId(userId)) { if (MatrixPatterns.isUserId(userId)) {
ParsedCommand.UnbanUser( ParsedCommand.UnbanUser(
userId, userId,
textMessage.substring(Command.UNBAN_USER.command.length + 1 + userId.length) textMessage.substring(Command.UNBAN_USER.length + userId.length)
.trim() .trim()
.takeIf { it.isNotBlank() } .takeIf { it.isNotBlank() }
) )

View file

@ -1181,7 +1181,7 @@ class RoomDetailFragment @Inject constructor(
&& userId == session.myUserId) { && userId == session.myUserId) {
// Empty composer, current user: start an emote // Empty composer, current user: start an emote
composerLayout.composerEditText.setText(Command.EMOTE.command + " ") composerLayout.composerEditText.setText(Command.EMOTE.command + " ")
composerLayout.composerEditText.setSelection(Command.EMOTE.command.length + 1) composerLayout.composerEditText.setSelection(Command.EMOTE.length)
} else { } else {
val roomMember = roomDetailViewModel.getMember(userId) val roomMember = roomDetailViewModel.getMember(userId)
// TODO move logic outside of fragment // TODO move logic outside of fragment