7

I have an NSTextView and require the coordinates of the insertion point to display a view there upon user interaction.

There is a function to get the character index from an NSPoint. I am wondering if there is any easy way to do the opposite?

Thanks for any help!

chaimp
  • 16,897
  • 16
  • 53
  • 86

2 Answers2

13

Sure: [textView firstRectForCharacterRange:[textView selectedRange]];

Ken
  • 12,933
  • 4
  • 29
  • 32
2

You might be able to do it with an NSTextView subclass, overriding -drawInsertionPointInRect:color:turnedOn: to cache the drawing rect and using the center of the rect (or some other interior point).

NB: I haven't tried this.

Wevah
  • 28,182
  • 7
  • 83
  • 72
  • Thank you for offering a solution. I ended up going with [textView firstRectForCharacterRange:[textView selectedRange]]; – chaimp Aug 28 '09 at 17:20