import SwiftUI

struct CustomEditor: UIViewRepresentable {
   @Binding var input: String

   func makeUIView(context: Context) -> UITextView {
      let view = UITextView()
      view.font = .systemFont(ofSize: 20)
      view.text = input
      view.delegate = context.coordinator
      return view
   }
   func updateUIView(_ uiView: UITextView, context: Context) {
      uiView.text = input
   }
   func makeCoordinator() -> CoordinatorTextView {
      return CoordinatorTextView(input: $input)
   }
}
class CoordinatorTextView: NSObject, UITextViewDelegate {
   @Binding var inputCoordinator: String

   init(input: Binding<String>) {
      self._inputCoordinator = input
   }
   func textViewDidChange(_ textView: UITextView) {
      inputCoordinator = textView.text
   }
   func textViewWritingToolsWillBegin(_ textView: UITextView) {
      print("Old Text: \(textView.text ?? "Empty")")
   }
   func textViewWritingToolsDidEnd(_ textView: UITextView) {
      print("New Text: \(textView.text ?? "Empty")")
   }
}