How to find caret position in an NSTextView?

后端 未结 2 1371
萌比男神i
萌比男神i 2020-12-14 22:18

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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-14 22:29

    For Swift 4

    let insertionPointIndex = myTextView.selectedRanges.first?.rangeValue.location
    

提交回复
热议问题