问题
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?
回答1:
NSInteger insertionPoint = [[[myTextView selectedRanges] objectAtIndex:0] rangeValue].location;
回答2:
For Swift 4
let insertionPointIndex = myTextView.selectedRanges.first?.rangeValue.location
来源:https://stackoverflow.com/questions/1701129/how-to-find-caret-position-in-an-nstextview