Reputation:
In a UiTextView i have a function to jump to the next character after the caret:
textView.selectedRange = NSMakeRange(textView.selectedRange.location+1,0);
When i have emoticons it doesn't work, i have to it twice.
I was wondering if i can check if the next character after the caret if a special character so i move 2 instead of 1 in caret location.
And when i try to get the NSString of thaT range it doesn't give anything or error
NSRange myRange = NSMakeRange(textView.selectedRange.location,1);
[textView.text substringWithRange:myRange]
Any help?
Upvotes: 4
Views: 830
Reputation: 318874
Use the NSString rangeOfComposedCharacterSequenceAtIndex:
method. For most characters this will return a range with a length of 1. But for characters with a Unicode value of U+10000 or more, this will give a range with a length of 2.
This will move the caret to the next character:
NSRange nextRange = [textView.text rangeOfComposedCharacterSequenceAtIndex:textView.selectedRange.location];
textView.selectedRange = NSMakeRange(nextRange.location + nextRange.length, 0);
Upvotes: 1