     /// Prepares the textView.
     fileprivate func prepareTextView() {
         textView = TextView(textContainer: textContainer)
+        textView.delegate = self
         addSubview(textView)
     }
     

     */
    @objc
    optional func editor(editor: Editor, didProcessEditing textStorage: TextStorage, text: String, range: NSRange)
}

open class Editor: View {

        delegate?.editor?(editor: self, didProcessEditing: textStorage, text: string, range: range)
    }
}

extension Editor: TextViewDelegate {
    open func textViewShouldBeginEditing(_ textView: UITextView) -> Bool {
        return delegate?.editor?(editor: self, shouldBeginEditing: textView) ?? true
    }
    
    open func textViewShouldEndEditing(_ textView: UITextView) -> Bool {
        return delegate?.editor?(editor: self, shouldEndEditing: textView) ?? true
    }
    
    open func textViewDidBeginEditing(_ textView: UITextView) {
        delegate?.editor?(editor: self, didBeginEditing: textView)
    }
    
    open func textViewDidEndEditing(_ textView: UITextView) {
        delegate?.editor?(editor: self, didEndEditing: textView)
    }
    
    open func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
        return delegate?.editor?(editor: self, textView: textView, shouldChangeTextIn: range, replacementText: text) ?? true
    }
    
    open func textViewDidChange(_ textView: UITextView) {
        delegate?.editor?(editor: self, didChange: textView)
    }
    
    open func textViewDidChangeSelection(_ textView: UITextView) {
        delegate?.editor?(editor: self, didChangeSelection: textView)
    }
}

@available(iOS 8.0, *)
extension Editor {
    open func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange) -> Bool {
        return true
    }
    
    open func textView(_ textView: UITextView, shouldInteractWith textAttachment: NSTextAttachment, in characterRange: NSRange) -> Bool {
        return true
    }
}

@available(iOS 10.0, *)
extension Editor {
    open func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
        return true
    }
    
    open func textView(_ textView: UITextView, shouldInteractWith textAttachment: NSTextAttachment, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
        return true
    }
}
