         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

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

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

        view?.m_attributedText?.enumerateAttribute(MentionAttributes.UserId, inRange: NSRange(location: 0, length: text.characters.count), options: NSAttributedStringEnumerationOptions(rawValue: 0)) { (value, range, stop) -> Void in
            guard let value = value as? Int else { return }
            if let length = self.mentionCache[value] where length != range.length + 1 {
                self.deleteMention(inRange: range)
                self.mentionCache.removeValueForKey(value)
                stop.memory = true
            }
        }

        if let query = mentionQuery(fromString: text) {
