On Sep 21, 2008, at 21:05 , Rick Mann wrote:
I want to implement a simple console for my app. As it generates data, it outputs a string representation of it to an NSTextView in a window. Already this was fairly cumbersome to do, but I got it working. The part that doesn't work is that it doesn't automatically scroll the text up after new text starts getting appended beyond the bottom of the window.How can I get it to do this?
You can do something like this: // assume textView is a pointer to the actual text view NSRange endRange = NSMakeRange([[textView string] length], 0); // assume string already contains the data to add to this text view [textView replaceCharactersInRange:endRange withString:string]; [textView scrollRangeToVisible:endRange]; [textView setNeedsDisplay:YES];
To complicate matters, how can I get it to do this only when the window was already scrolled to the bottom, and not when scrolled elsewhere (in the same fashion as Terminal.app)?
You would have to track whether or not the text view is at the end. I suggest looking at the documentation for NSTextView as well as the Scroll View Programming Guide:
http://developer.apple.com/documentation/Cocoa/Conceptual/NSScrollViewGuide/Articles/Introduction.html HTH, Jason
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ 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 [EMAIL PROTECTED]