Question

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!

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top