 
     fileprivate var textStore = NSMutableAttributedString(string: "", attributes: nil)
 
+    fileprivate var textStoreString = ""
+
 
     // MARK: - Delegates
 

        detectAttachmentRemoved(in: range)
        textStore.replaceCharacters(in: range, with: str)

        edited(.editedCharacters, range: range, changeInLength: str.characters.count - range.length)
        
        endEditing()


        detectAttachmentRemoved(in: range)
        textStore.replaceCharacters(in: range, with: preprocessedString)

        let utf16String = textStoreString.utf16
        let startIndex = utf16String.index(utf16String.startIndex, offsetBy: range.location)
        let endIndex = utf16String.index(startIndex, offsetBy: range.length)
        textStoreString.replaceSubrange(startIndex..<endIndex, with: attrString.string)

        edited([.editedAttributes, .editedCharacters], range: range, changeInLength: attrString.length - range.length)

        endEditing()
