Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Mactrix/Views/ChatView/FormattedBodyView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading