Re: Programmatically inserting text into NSTextView and scrolling
Re: Programmatically inserting text into NSTextView and scrolling
- Subject: Re: Programmatically inserting text into NSTextView and scrolling
- From: Jason Coco <email@hidden>
- Date: Sun, 21 Sep 2008 21:32:58 -0400
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
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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