Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
In FakeViewActionCollector, replace the mentions text with either a…
Browse files Browse the repository at this point in the history
…n `@mentionText` or a proper link.
  • Loading branch information
jmartinesp committed Nov 2, 2023
1 parent d1ca6a4 commit 438441d
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ internal class FakeViewActionCollector(
ViewAction.ToggleQuote -> toggleQuote()
ViewAction.Undo -> undo()
ViewAction.Unindent -> unindent()
is ViewAction.ReplaceSuggestionText -> state.menuAction = MenuAction.None
is ViewAction.InsertMentionAtSuggestion -> state.menuAction = MenuAction.None
is ViewAction.ReplaceSuggestionText -> {
state.messageHtml = state.messageHtml.replaceLast(Regex("(@\\w+)"), value.text)
}
is ViewAction.InsertMentionAtSuggestion -> {
state.messageHtml = state.messageHtml.replaceLast(Regex("(@\\w+)"), "<a href='${value.url}'>${value.text}</a>")
}
}
}
private fun toggleInlineFormat(inlineFormat: InlineFormat): Boolean {
Expand Down Expand Up @@ -130,6 +134,13 @@ internal class FakeViewActionCollector(
actions[action] = newAction
state.actions = actions
}

private fun String.replaceLast(regex: Regex, value: String): String {
val lastMatch = regex.findAll(this).lastOrNull()
return lastMatch?.let {
replaceRange(it.range, value)
} ?: this
}
}

private fun InlineFormat.toComposerAction() = when (this) {
Expand Down

0 comments on commit 438441d

Please sign in to comment.