Re: Scrolling Behavior of NSTextView
Re: Scrolling Behavior of NSTextView
- Subject: Re: Scrolling Behavior of NSTextView
- From: "Paul Sanders" <email@hidden>
- Date: Tue, 8 Jun 2010 11:46:56 +0100
> Martin, I tried the " [NSTextView scrollRangeToVisible:] with NSMakeRange(0,0) ", but it is the same as to use [scrollPoint:] solely. Only with
> [glyphRangeForTextContainer:] in prior the scroll-to-top works. I don't think it is the problem of coordinate system flip-ness, because when using
> [scrollPoint:] without [glyphRangeForTextContainer:], the text view does not always scroll to bottom, either, it just does not always scroll to top under
> certain window size and text length. And it seems not solely [glyphRangeForTextContainer:] triggers the scroll-to-top because without [scrollPoint:] the
> scrolling does not work, either.
I thank Martin is right though - the fact that the coordinate system is flipped means that it is not necessary to know the dimensions of the text in order to position point (0, 0) in the top-lefthand corner. And just calling glyphRangeForTextContainer: on its own will not cause any scrolling.
> Another minor wired problem is the trick of using both [glyphRangeForTextContainer:] and [scrollPoint:] works only when you drag-drop a NSScrollView
> in IB and then set the embedded custom view as NSTextView. If an NSTextView is dragged and dropped directly (and IB automatically embed it in a
> NSScrollView), the scroll-to-top does not work even with the trick (and I haven't found a trick to make it work under such situation).
That would seem to point to some difference in the way the NSTextView is initialised by IB, although I'm not sure what. Using a custom view is clearly undesirable as you cannot set the properties of the text view in IB that way.
You could try calling displayIfNeeded on the enclosing scroll view before calling scrollPoint:. This ought to perform any necessary layout and maybe one or two other things. It shouldn't cause any screen flash because the window will not be flushed until you return to the run loop. You can get hold of the enclosing scroll view via [[myTextView superview] superview].
I also thought that Martin's idea of putting a breakpoint on [NSTextView scrollPoint:] might turn up something interesting. You could also put a breakpoint on [NSTextView setBounds:] as that is what scrollPoint: will ultimately call, see:
http://developer.apple.com/mac/library/documentation/cocoa/Conceptual/NSScrollViewGuide/Articles/Basics.html#//apple_ref/doc/uid/TP40003461-SW1
Regards,
Paul Sanders
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden