Skip to content
Open
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
35 changes: 31 additions & 4 deletions Mactrix/Views/ChatView/ChatInputView/ChatTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import SwiftUI

struct ChatTextView: NSViewRepresentable {
typealias NSViewRepresentableType = NSTextView

@AppStorage("fontSize") var fontSize: Int = 13

let text: Binding<String>
let placeholder: String
Expand All @@ -17,7 +19,10 @@ struct ChatTextView: NSViewRepresentable {

textView.placeholderAttributedString = NSAttributedString(
string: placeholder,
attributes: [.foregroundColor: NSColor.secondaryLabelColor]
attributes: [
.foregroundColor: NSColor.secondaryLabelColor,
.font: NSFont.systemFont(ofSize: CGFloat(fontSize))
]
)

textView.backgroundColor = .clear
Expand All @@ -34,6 +39,8 @@ struct ChatTextView: NSViewRepresentable {

textView.setContentHuggingPriority(.required, for: .vertical)
textView.setContentCompressionResistancePriority(.required, for: .vertical)

textView.font = NSFont.systemFont(ofSize: CGFloat(fontSize))

return textView
}
Expand All @@ -47,11 +54,25 @@ struct ChatTextView: NSViewRepresentable {
textView.string = text.wrappedValue
textView.invalidateIntrinsicContentSize()
}

if textView.placeholderAttributedString?.string != placeholder {

let currentPlaceholderFont =
textView.placeholderAttributedString?
.attribute(
.font,
at: 0,
effectiveRange: nil
) as? NSFont
let placeholderFontChanged =
currentPlaceholderFont?.pointSize != CGFloat(fontSize)
if textView.placeholderAttributedString?.string != placeholder ||
placeholderFontChanged
{
textView.placeholderAttributedString = NSAttributedString(
string: placeholder,
attributes: [.foregroundColor: NSColor.secondaryLabelColor]
attributes: [
.foregroundColor: NSColor.secondaryLabelColor,
.font: NSFont.systemFont(ofSize: CGFloat(fontSize))
]
)
}

Expand All @@ -65,6 +86,12 @@ struct ChatTextView: NSViewRepresentable {
unsafe textView.window?.makeFirstResponder(nil)
}
}

let currentFont = NSFont.systemFont(ofSize: CGFloat(fontSize))
if textView.font?.pointSize != currentFont.pointSize {
textView.font = currentFont
textView.invalidateIntrinsicContentSize()
}
}

func makeCoordinator() -> Coordinator {
Expand Down