Location screen location in NSTextView

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

I tried several code options below, but can't get the result I need - is it NSClipView by screwing it in?

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

Any ideas?

Hooray!

MT

+3
source share
1 answer

According to the documentation, the location of the glyph refers to its fragment of the environment. You must adjust the point using the rectangle of the line fragment. This should fix the variation you see.

+1

Source: https://habr.com/ru/post/1732334/


All Articles