How to find caret position in an NSTextView?

2020-02-08 18:45发布

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?

2条回答
女痞
2楼-- · 2020-02-08 19:01
NSInteger insertionPoint = [[[myTextView selectedRanges] objectAtIndex:0] rangeValue].location;
查看更多
够拽才男人
3楼-- · 2020-02-08 19:04

For Swift 4

let insertionPointIndex = myTextView.selectedRanges.first?.rangeValue.location
查看更多
登录 后发表回答