Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I figured it out. I used none of the suggestions above. That being said, the performance I am getting now is simply incredible. Keep in mind that YMMV. The way you tokenize and cache meta-data about your string may be different than me. However, I was able to type in a 1400 line PHP file and it took only 0.015 seconds for any one change to complete. Simply incredible.</p> <p>Here is the approach I took:</p> <p>My UIViewController is a delegate to UITextViewDelegate and UIScrollViewDelegate.</p> <p>When UITextViewDelegate.textViewDidChange: is called I determine which range of text is currently visible to the end-user. I did this by using my existing sub-classed UITextView and adding this method to it:</p> <pre><code>- (NSRange)visibleRangeOfText { CGRect bounds = self.bounds; UITextPosition *start = [self characterRangeAtPoint:bounds.origin].start; UITextPosition *end = [self characterRangeAtPoint:CGPointMake(CGRectGetMaxX(bounds), CGRectGetMaxY(bounds))].end; return NSMakeRange([self offsetFromPosition:self.beginningOfDocument toPosition:start], [self offsetFromPosition:start toPosition:end]); } </code></pre> <p>After that, I pass the range to a subclassed NSTextStorage object, where it will then perform the magic to determine which lines need to be highlighted.</p> <p>The same goes for the UIScollViewDelegate method calls. Depending on which part of the view is being viewed I pass in the visible range to my subclassed NSTextStorage call and it determines if the lines have already been attributed, etc.</p> <p>I realize I'm leaving a lot up to the reader. I ended up using what I currently had and tweaked it a bit to work with the above implementation.</p> <p>I wanted to share some of my discoveries that I found interesting while implementing this:</p> <p>1) If you attempt to highlight any text ABOVE the current line, where the cursor is resting, you may see that the cursor "jumps" up within the view, and then settles back to the position where it was originally. I am almost positive this is caused by the NSTextStorage.processEditing method call. I was able to get it to where the system only highlights the line that was modified... so this issue is gone now.</p> <p>2) Originally I did this to prevent the cursor from jumping around:</p> <pre><code>NSRange selectedRange = [textView selectedTextRange]; [textView setScrollEnabled:NO]; NSRange visibleRange = [textView visibleRangeOfText]; [textStorage applyAttributesToRange:visibleRange]; [textView setScrollEnabled:YES]; </code></pre> <p>It worked... but the [textView setScrollEnabled:NO] call made a MASSIVE hit to performance. It took nearly 3/4 of a second for that command alone to finish on a 1400 line file. I'm not sure what causes it to be slow but I thought it was worth mentioning.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload