简体   繁体   中英

How to find caret position in an NSTextView?

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?

NSInteger insertionPoint = [[[myTextView selectedRanges] objectAtIndex:0] rangeValue].location;

对于Swift 4

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM