title: Modifying NSTextStorage attributes causes scroll view to jump around
body: <p>I have implemented basic syntax highlighting by properly setting the <code>NSTextStorage</code> delegate of my <code>NSTextView</code> and changing the text attributes in <code>-textStorageDidProcessEditing</code>.</p>
  
  <p>The basic process is as follows</p>
  
  <pre><code>- (void)textStorageDidProcessEditing:(NSNotification *)notification {
    NSTextStorage *storage = [notification object];
    [storage beginEditing];
  
    NSString *text = [storage string];
    NSRange textRange = NSMakeRange(0, [text length]);
  
    [storage removeAttribute:NSForegroundColorAttributeName range:textRange];
  
    // Some regex matching here ...
  
    [storage addAttribute:NSForegroundColorAttributeName
                    value:[COSyntax colorForPatternGroup:pattern.groupName]
                    range:capturedRanges[group]];
  
    [storage endEditing];
  }
  </code></pre>
  
  <p>Whenever <code>-removeAttribute:range:</code> or <code>-addAttribute:value:range</code> is invoked when a <code>SPACE</code> character is entered, the <code>NSTextView</code>s surrounding <code>NSScrollView</code> location begins to jump around (scroll knob goes to some random position near the )</p>
  
  <p>What's causing this?</p>