title: Technique on how to format/color NSTextView's string
body: <p>I'm looking for a reliable technique to do simple string formatting(bold, italic,...) in a NSTextView. The text parsing is almost done with regex, but now I need to apply font trait and also change the size. </p>
  
  <p>Some code snippets on how I make a text bold</p>
  
  <pre><code>[[textView textStorage] beginEditing];
  [[textView textStorage] applyFontTraits:NSFontBoldTrait range:range];
  [[textView textStorage] endEditing];
  </code></pre>
  
  <p>This and also the size changes with</p>
  
  <pre><code>[[textView textStorage] beginEditing];  
  NSFont* font = [[textView textStorage] attribute:NSFontAttributeName atIndex:range.location effectiveRange:nil];
  
  NSFont* newFont = [NSFont fontWithName:[font familyName] 
                                    size:[font pointSize] + size];
  
  [[textView textStorage] addAttribute:NSFontAttributeName 
                                 value:newFont 
                                 range:range];
  [[textView textStorage] endEditing];
  </code></pre>
  
  <p>works fine. The only problem I have now is that in some cases, when I type new characters, those characters are bold or italic by default, even though I don't apply the properties to them. </p>
  
  <p>Do I have to reset something with the <code>setTypingAttributes</code> of the <code>NSTextView</code> or do I simply miss something here?</p>