- (NSRect)rectForActiveRange {
NSLayoutManager *l = [self layoutManager];
NSRange range = [l glyphRangeForCharacterRange:self.activeRange actualCharacterRange:nil];
NSRect rect = [l boundingRectForGlyphRange:range inTextContainer:[self textContainer]];
rect = NSOffsetRect(rect, self.textContainerOrigin.x, self.textContainerOrigin.y);
return rect;
}
activeRange == selectedRange WHICH is the selection range OR if there is selection a range of length 0 from right where you type
see also: http://www.cocoabuilder.com/archive/cocoa/158706-how-to-find-the-insertion-point-of-nstextview.html