On 2010.06.07, at 2:10 PM, Paul Sanders wrote:

I encountered a wired behavior of NSTextView. I tried to use the following statement to scroll to top:
[[_scrollView documentView] scrollPoint:NSMakePoint(0, 0)];

where the *documentView* is a NSTextView. But it seems when the window is in certain size, the scroll-to-top behavior does not take effect. Then I added a seemingly irrelevant statement before the above statement, by accidental,
so the fragment become the follows:

[[[_scrollView documentView] layoutManager] glyphRangeForTextContainer:[[self dictionaryContent] textContainer]];
[[_scrollView documentView] scrollPoint:NSMakePoint(0, 0)];

The complete source code is at http://techsingular.net/dict_mac/dict_mac.dmg

The problem happens when you search for "灵" or "神" through this dictionary program.

I haven't looked at your code so I don't know what is going on in detail but [NSLayoutManager glyphRangeForTextContainer:] performs layout, if it hasn't been done already, which is probably why it is affecting the results you get. Until layout has been performed, the Cocoa text system doesn't know the size of the text (in terms of the amount of space it will take up on the display) and so (I surmise) scrollPoint: doesn't work as expected.

You're right about triggering layout, but there's no reason the text system should have any trouble with NSMakePoint(0,0). NSTextView and the Cocoa layout system always use a flipped coordinate system, so the origin is always top-left.

Perhaps the problem is that once layout completes (or during layout), you (or Cocoa) is automatically scrolling the text view somewhere else? I'd break in the debugger to see if anything else is triggering unwanted scrolling.

~Martin

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to