ruipacheco
ruipacheco

Reputation: 16402

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?

Upvotes: 12

Views: 7164

Answers (2)

Jay Mehta
Jay Mehta

Reputation: 1791

For Swift 4

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

Upvotes: 4

Art Gillespie
Art Gillespie

Reputation: 8757

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

Upvotes: 31

Related Questions