Fix editing formatted messages in plain text editor (#7360)
* Fix editing formatted messages in plain text editor * Update changelog.d/7359.sdk Co-authored-by: Benoit Marty <benoitm@matrix.org> Co-authored-by: Benoit Marty <benoitm@matrix.org>
This commit is contained in:
parent
612d2e51e5
commit
f1acb4712c
|
@ -0,0 +1 @@
|
|||
Fix editing formatted messages with plain text editor
|
|
@ -0,0 +1 @@
|
|||
Allow getting the formatted or plain text body of a message for the fun `TimelineEvent.getTextEditableContent()`.
|
|
@ -181,9 +181,13 @@ fun TimelineEvent.isRootThread(): Boolean {
|
|||
/**
|
||||
* Get the latest message body, after a possible edition, stripping the reply prefix if necessary.
|
||||
*/
|
||||
fun TimelineEvent.getTextEditableContent(): String {
|
||||
fun TimelineEvent.getTextEditableContent(formatted: Boolean): String {
|
||||
val lastMessageContent = getLastMessageContent()
|
||||
val lastContentBody = lastMessageContent.getFormattedBody() ?: return ""
|
||||
val lastContentBody = if (formatted && lastMessageContent is MessageContentWithFormattedBody) {
|
||||
lastMessageContent.formattedBody
|
||||
} else {
|
||||
lastMessageContent?.body
|
||||
} ?: return ""
|
||||
return if (isReply()) {
|
||||
extractUsefulTextFromReply(lastContentBody)
|
||||
} else {
|
||||
|
@ -201,11 +205,3 @@ fun MessageContent.getTextDisplayableContent(): String {
|
|||
?: (this as MessageTextContent?)?.matrixFormattedBody?.let { ContentUtils.formatSpoilerTextFromHtml(it) }
|
||||
?: body
|
||||
}
|
||||
|
||||
fun MessageContent?.getFormattedBody(): String? {
|
||||
return if (this is MessageContentWithFormattedBody) {
|
||||
formattedBody
|
||||
} else {
|
||||
this?.body
|
||||
}
|
||||
}
|
||||
|
|
|
@ -151,7 +151,8 @@ class MessageComposerViewModel @AssistedInject constructor(
|
|||
|
||||
private fun handleEnterEditMode(action: MessageComposerAction.EnterEditMode) {
|
||||
room.getTimelineEvent(action.eventId)?.let { timelineEvent ->
|
||||
setState { copy(sendMode = SendMode.Edit(timelineEvent, timelineEvent.getTextEditableContent())) }
|
||||
val formatted = vectorPreferences.isRichTextEditorEnabled()
|
||||
setState { copy(sendMode = SendMode.Edit(timelineEvent, timelineEvent.getTextEditableContent(formatted))) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -552,7 +553,7 @@ class MessageComposerViewModel @AssistedInject constructor(
|
|||
state.sendMode.timelineEvent,
|
||||
messageContent?.msgType ?: MessageType.MSGTYPE_TEXT,
|
||||
action.text,
|
||||
(messageContent as? MessageContentWithFormattedBody)?.formattedBody,
|
||||
action.formattedText,
|
||||
action.autoMarkdown
|
||||
)
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue