views:

20

answers:

1

All,

I'm tweaking an NSTextView to basically support insertion of boiler plate text and indenting. I'm running into a problem where the indenting of boiler plate text is applied to non-boiler plate text after I remove the boiler plate indenting style from the edited range (i remove the style when the user hits enter). Here's where things get weird:

With the text ruler exposed in the editor, I'm seeing behaviour that changes the indent. After the return key is entered, I run the following code:

NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; 
[style setTabStops: [NSArray array]];
[style setHeadIndent:0];
[style setFirstLineHeadIndent:0];
NSRange effectiveRange = [textView rangeForUserTextChange];
[self applyStyleToRange:effectiveRange style:style];
[style release];

Initially, this works, but if I move my cursor up to the boiler-plated, indented text above this new line, the tab stop reappears and doesn't go away when I move the cursor back down to the new line the carriage return created. It seems to me that the style of the prior paragraph is being applied to the new paragraph.

I've put a video up on the web (30 seconds 1.3 MB) that shows the problem:

http://gordonjl.com/files/indentingProblem%20-%20Computer.m4v

Also: Yes, this is a terrible way to do this, but this is the last bug for this release and I have to ship it. In a subsequent release I'm hoping to insert NSTextViews into a scroll area and manage it in a more explicit manner. Until then, help!

A: 

I don't really understand your objective but FWIW, if you are setting a paragraph attribute you might want to use rangeForUserParagraphChange. If cursor is at end of textStorage, you must set the textView's typingAttributes because it is meaningless to apply an attribute to an empty range.

Ross Carter