diff --git a/Mactrix/Views/ChatView/FormattedBodyView.swift b/Mactrix/Views/ChatView/FormattedBodyView.swift index d1c0f17..149f688 100644 --- a/Mactrix/Views/ChatView/FormattedBodyView.swift +++ b/Mactrix/Views/ChatView/FormattedBodyView.swift @@ -6,21 +6,21 @@ struct FormattedBodyView: View { @AppStorage("fontSize") private var fontSize = 13 let rawBody: String - let htmlBody: String? + var formattedBody: AttributedString? = nil init(messageContent: some MessageContent) { self.rawBody = messageContent.body if let formatted = messageContent.formatted, formatted.format == .html { - self.htmlBody = formatted.body - } else { - self.htmlBody = nil + let parsed = parseFormattedBody(formatted.body, baseFontSize: CGFloat(fontSize)) + self.formattedBody = AttributedString(parsed.trimmed) } } var body: some View { - if let htmlBody { - AttributedTextView(attributedString: parseFormattedBody(htmlBody, baseFontSize: CGFloat(fontSize))) + if let formattedBody { + Text(formattedBody) + .textSelection(.enabled) .fixedSize(horizontal: false, vertical: true) } else { Text(rawBody) diff --git a/MactrixLibrary/Sources/MessageFormatting/AttributedTextView.swift b/MactrixLibrary/Sources/MessageFormatting/AttributedTextView.swift index 73a4d9a..7764b85 100644 --- a/MactrixLibrary/Sources/MessageFormatting/AttributedTextView.swift +++ b/MactrixLibrary/Sources/MessageFormatting/AttributedTextView.swift @@ -40,7 +40,7 @@ public struct AttributedTextView: NSViewRepresentable { } extension NSAttributedString { - var trimmed: NSAttributedString { + public var trimmed: NSAttributedString { let nonWhitespaces = CharacterSet.whitespacesAndNewlines.inverted let startRange = string.rangeOfCharacter(from: nonWhitespaces) let endRange = string.rangeOfCharacter(from: nonWhitespaces, options: .backwards)