             // Reset to prevText if you tried to change parkedText.
             if !text.hasSuffix(parkedText) {
                 let attributedString = NSMutableAttributedString(string: prevText)
-                attributedString.addAttributes(parkedTextAttributes, range: NSMakeRange(count(prevText)-count(parkedText), count(parkedText)))
+
+                let range = prevText.rangeOfString(parkedText, options: NSStringCompareOptions.BackwardsSearch, range: nil, locale: nil)
+                let nsrange = NSRangeFromRange(prevText, range: range!)
+
+                attributedString.addAttributes(parkedTextAttributes, range: nsrange)
                 attributedText = attributedString
             } else {
                 prevText = text
-                notParkedText = text[0..<count(text) - count(parkedText)]
+
+                notParkedText = text[text.startIndex..<advance(text.endIndex, -count(parkedText))]
             }
             goToBeginningOfConstantText()
 

        switch typingState {
        case .Start where count(text) > 0:
            notParkedText = text
            
            let attributedString = NSMutableAttributedString(string: text + parkedText)
            attributedString.addAttributes(parkedTextAttributes, range: NSMakeRange(count(text), count(parkedText)))
            attributedText = attributedString

            prevText = text

            return nil
        }
    }
}