I am trying to a text parser for iOS. I have some syntax to bold, italic, highlight, etc. I have set it up in a UITextView
with an instance of NSTextStorage
to monitor the changes and set the correct attributes. If I preload the UITextView
with text it works great.
However when I'm typing and let's say I type something like this
==a==
It works great it highlights it yellow and everything is fine. However if I place the cursor right next to the last ==
and starting typing to create something like this:
==a==hello my name is...
Then the rest of the text also gets highlighted.
I know the regex I use is not the problem because if I pre fill the UITextView
with that text it parses it correctly.
Question: So what I need help with is resetting the the current cursor position to no text attributes. I'm not sure how to do that because if it is at the end of the text view I can't go forward because then I get an NSRangeException
.
Thanks!