Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Perkin

macrumors newbie
Original poster
Oct 22, 2013
16
0
Hi, I'm working on a NSTextView, with Syntax Highlighting, and have got it working pretty well, my problem however is when editing in the TextView and press return in middle of a line only the previous line is re-styled, and the current line is'nt,

My question is how can I extend the range to restyle both.

Any help will be appreciated.

Further Detail:
Say I have the text
Code:
_*Bold and Italics*_
which is styled by the highlighter by matching the _* and the *_, styles them and text inbetween bold, italic and red

If I place cursor between the 'a' and 'n' of the word 'and' and then press return, breaking it onto two lines, the front half gets reset to unstyled text, whereas the 'nd Italics*_' loses the bold and italic styling, but stays red.
If I then press space and delete then that would also reset to unstyled text

The top of my processEditing is as follows
Code:
- (void)processEditing
{
    [super processEditing];
    
	// Reset text style of edited range
	NSRange paragaphRange = [self.string paragraphRangeForRange: self.editedRange];
    
    [self removeAttribute:NSForegroundColorAttributeName range:paragaphRange];
    [self removeAttribute:NSBackgroundColorAttributeName range:paragaphRange];
    [self removeAttribute:NSUnderlineStyleAttributeName range:paragaphRange];
    [self applyFontTraits:NSUnboldFontMask range:paragaphRange];
    [self applyFontTraits:NSUnitalicFontMask range:paragaphRange];

I then loop through a series of pre-made regexes which styles the edited text.

What I don't get is why the second half loses the bold and italic but stays red, why don't all three get reset?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.