• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSTextView scroll is really slow!! How do I achieve fast scrolling like Terminal App?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSTextView scroll is really slow!! How do I achieve fast scrolling like Terminal App?


  • Subject: NSTextView scroll is really slow!! How do I achieve fast scrolling like Terminal App?
  • From: Christopher Woodruff <email@hidden>
  • Date: Wed, 14 Nov 2007 18:23:10 -0800

I've read a lot threads on the email lists about how to set up an automatically vertically scrolling view similar to a terminal view. I want new text to appear at the bottom of a textview and the scroll bar position to remain at the bottom, unless the user has moved it to look at some text. Basically I want a window that displays text output that behaves and performs exactly like the Terminal application or the Run Log in XCode.

I have attempted to do this by appending my text data to the textStorage mutableString. To control the scroll bar position, I use the scrollToVisibleRange method. Unfortunately, I have read about and experienced the performance hit when using this method (It is supposedly O(N) for the number of lines).

I know that this can be done because I see that the Run Log in Xcode and the Terminal have this behavior without getting the spinning ball when it updates more than 10 lines a second. Can someone give me a hint at a more efficient way to achieve this behavior?

Here my current implementation for the textview:

- (void)updateReceiverConsole:(NSNotification *)aNotification
{
float scrollPos = [[receiverScroll verticalScroller] floatValue]; // Get the current scrollbar position

NSString *aLogMessage = [aNotification object];
if(!aLogMessage==nil) //Append the new text to the textStorage mutableString
{
[[[receiverConsole textStorage] mutableString ] appendString:aLogMessage];
}

// Delete the old lines of text to keep the text a set number of lines
if([[[receiverConsole textStorage] paragraphs] count]>50)
{
[[receiverConsole textStorage] deleteCharactersInRange:NSMakeRange (0, [[[[receiverConsole textStorage] paragraphs] objectAtIndex:0] length])];
}

// if the scrollbar *was all the way at the bottom before the new text was appended,
// then scroll down to the bottom
if( scrollPos == 1.0 )
{
NSRange range;
range = NSMakeRange ([[receiverConsole string] length], 0);

[receiverConsole scrollRangeToVisible: range]; //This method is O (N) for the number of lines!
}
}


Cheers,

Chris Woodruff

Jet Propulsion Laboratory
M/S: 138-206
4800 Oak Grove Dr.
Pasadena, CA 91109
818-354-2412


_______________________________________________

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


  • Prev by Date: NSTextView/NSScrollView update problems
  • Next by Date: Scripting Bridge question
  • Previous by thread: NSTextView/NSScrollView update problems
  • Next by thread: Scripting Bridge question
  • Index(es):
    • Date
    • Thread