6

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!

Hovanky
  • 303
  • 1
  • 3
  • 15

1 Answers1

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

Daij-Djan
  • 49,552
  • 17
  • 113
  • 135