How do I get just the visible text from an NSTextView?

the idea is, I want to know what’s visible in the window at any given time (through a delegate, I guess, right?), parse it, use it to present contextualized info in a second window.

doesn’t seem like this should be too hard, I just don’t know how to do it :slight_smile:

wow, I guess it’s harder than I thought. Isn’t there SOME way to get contents of current page in scrollview, or array of line fragments from nslayoutmanager, current glyph range from the nslayoutmanager or something? anything?

I have a note out to mike ash and one out to a textkit expert in japan.

I think something like this is the answer

(NSRange)glyphRangeForBoundingRectWithoutAdditionalLayout:(CGRect)bounds inTextContainer:(NSTextContainer *)container;

then use the glyph index to access the range in the character index

someone also responded with this to my question on stackoverflow:

also of interest.