Question

I want to get the screen location (NSPoint) of a point in an NSTextView, this should be simple, but by results are always a bit off, the X is perfect, but the Y seems to vary.

I've tried a few variations of the code below, but can't get the result I'm after, is the NSClipView screwing it up?

NSPoint p = [[self layoutManager] locationForGlyphAtIndex:r.location];
//NSPoint b= [self convertPoint:p toView:nil];
NSPoint screenlocation = [self convertPointToBase:p];

Any ideas?

Cheers!

MT

Was it helpful?

Solution

According to the documentation, the location for a glyph is relative to its enclosing line fragment. You should adjust the point by using the rectangle of the line fragment. That should fix the variation you see.

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