0
votes

I have an NSTextView control object wrapped with NSScrollView. What I want to do is to make the text string at the current position visible when it's hidden below the content view.

enter image description here

In reference to the picture above, with

NSUInteger cPosition = [[[textView1 selectedRanges] objectAtIndex:0] rangeValue].location;
[textView1 scrollRangeToVisible:NSMakeRange(0,cPosition)];

the scroll view will scroll itself to a position such that the selected string (document) will come at the bottom of the content view. (Line 11). That's not exactly what I want. I would like the scroll view to scroll itself to show the text string at the current cursor position when it's hidden below the content view (for example, at Line 14). How can I improve my code?

Muchos thankos.

1

1 Answers

1
votes

One solution would be to use NSString's enumerateSubstringsInRange:options:usingBlock: method with the NSStringEnumerationByParagraphs option and passing the range that contains your cPosition to scrollRangeToVisible:. This would have the effect of making the paragraph that contains your cPosition visible.