Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSTextview: How do I get the glyph rect of the insertion point ? Custom TextView?

I can't seem to find any documentation about how to get the rect of the insertion point. I'm trying to display a view (like auto-complete) directly below the text caret / insertion point

I'm considering making a custom textview but if i could avoid it , that would be ideal in my situation. Thanks!

like image 473
Hovanky Avatar asked May 05 '13 17:05

Hovanky


1 Answers

- (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

like image 129
Daij-Djan Avatar answered Oct 04 '22 00:10

Daij-Djan