     private let originalAutoCorrectionType: UITextAutocorrectionType!
     private var userNameMatches: [MentionUser]?
     private var previousCharacterCount = 0
+
+    private var mentionCache = [Int : Int]()
+
     private var recentCharacterRange: NSRange {
         guard let
             beginning = view?.beginningOfDocument,

    func textChanged() {
        guard let text = view?.m_text else { return }

        let deleting = view?.m_attributedText?.string.characters.count < previousCharacterCount
        if let range = rangeOfMention(atIndex: recentCharacterRange.location) {
            deleting ? deleteMention(inRange: range) : undoMention(inRange: range)
        }

        if let query = mentionQuery(fromString: text) {

        let mutableEncodedString = NSMutableAttributedString(attributedString: user.encodedAttributedString())
        mutableEncodedString.addAttributes([NSFontAttributeName : font, NSForegroundColorAttributeName : MentionColor], range: NSRange(location: 0, length: mutableEncodedString.length))
        text.replaceCharactersInRange(mentionRange!, withAttributedString: mutableEncodedString)
        mentionCache[user.id] = mutableEncodedString.length
        let typingAttributes = view?.m_typingAttributes
        setAttributedText(text, cursorLocation: mentionRange!.location + mutableEncodedString.length)
        view?.m_typingAttributes = typingAttributes
