     }
 
     // MARK: Utilites
+
+    /// http://stackoverflow.com/questions/25138339/nsrange-to-rangestring-index
+    func NSRangeFromRange(text:String, range : Range<String.Index>) -> NSRange {
+        let utf16view = text.utf16
+        let from = String.UTF16View.Index(range.startIndex, within: utf16view)
+        let to = String.UTF16View.Index(range.endIndex, within: utf16view)
+        return NSMakeRange(from - utf16view.startIndex, to - from)
+    }
+
     func goToBeginningOfConstantText() {
         if let position = beginningOfConstantText {
             goToTextPosition(position)

        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

            // Reset to prevText if you tried to change parkedText.
            if !text.hasSuffix(parkedText) {
                let attributedString = NSMutableAttributedString(string: prevText)

                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[text.startIndex..<advance(text.endIndex, -count(parkedText))]
            }
            goToBeginningOfConstantText()

