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!
- (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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.