How to find caret position in an NSTextView?

后端 未结 2 1370
萌比男神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条回答
  • 2020-12-14 22:29

    For Swift 4

    let insertionPointIndex = myTextView.selectedRanges.first?.rangeValue.location
    
    0 讨论(0)
  • 2020-12-14 22:37
    NSInteger insertionPoint = [[[myTextView selectedRanges] objectAtIndex:0] rangeValue].location;
    
    0 讨论(0)
提交回复
热议问题