import SwiftUI

struct CustomEditor: UIViewRepresentable {
   @Binding var input: NSAttributedString

   func makeUIView(context: Context) -> UITextView {
      let view = UITextView()
      view.isEditable = true
      view.allowsEditingTextAttributes = true
      view.supportsAdaptiveImageGlyph = true
      view.delegate = context.coordinator

      let defaultFont = UIFont.systemFont(ofSize: 20)
      view.typingAttributes[.font] = defaultFont
      view.attributedText = input
      return view
   }
   func updateUIView(_ uiView: UITextView, context: Context) {
      uiView.attributedText = input
   }
   func makeCoordinator() -> CoordinatorTextView {
      return CoordinatorTextView(input: $input)
   }
}
class CoordinatorTextView: NSObject, UITextViewDelegate {
   @Binding var inputCoordinator: NSAttributedString

   init(input: Binding<NSAttributedString>) {
      self._inputCoordinator = input
   }
   func textViewDidChange(_ textView: UITextView) {
      inputCoordinator = textView.attributedText
   }
}