How to find caret position in an NSTextView?
-
19-09-2019 - |
Question
I've an NSTextView with with several semi-colon separated strings. I need to find on which of those strings the caret has been placed. How could I do that?
Solution
NSInteger insertionPoint = [[[myTextView selectedRanges] objectAtIndex:0] rangeValue].location;
OTHER TIPS
For Swift 4
let insertionPointIndex = myTextView.selectedRanges.first?.rangeValue.location
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow