OK, bug found. 

A really silly mistake on my part but I think it's worth reporting in case it 
saves someone else a headache. 

My NSTextView subclass has syntax coloring which is called on receipt of 
NSTextStorageDidProcessEditingNotification.

In the method that does the coloring, I had the following:


        [[self textStorage] beginEditing];

        [self setTextColor:textColor range:r];

        // do other coloring stuff by setting attributes on the NSTextStorage, 
e.g.,
        [[self textStorage] addAttribute:NSForegroundColorAttributeName 
value:commentColor range:commRange];

        // ..... other stuff

        [[self textStorage] endEditing];


So I think it is a bad thing to make calls to NSTextView methods which change 
the text in between calls to begin/endEditing. So moving the setTextColor: call 
above beginEditing fixes the problem.

I still don't understand why it is depending on initializing the text storage 
with an empty string or not. Still some head scratching to do, I think.

Martin




On Apr 8, 2010, at 5:57 AM, Martin Hewitson wrote:

> 
> On Apr 7, 2010, at 10:50 PM, Ross Carter wrote:
> 
>> On Apr 7, 2010, at 11:52 AM, Martin Hewitson <[email protected]> 
>> wrote:
>> 
>>> Hi Kyle,
>>> 
>>> At the moment it does nothing but call super. I was using it to handle 
>>> line-wrapping, but in the process of debugging this problem it's reduced to
>>> 
>>> - (void)insertText:(id)aString
>>> {
>>>     [super insertText:aString];
>>> }
>> 
>> I would set a breakpoint here and examine a description of the textStorage 
>> and the layoutManager. Also, are you creating the NSTextStorage from an 
>> empty string? Nil? Or possibly some other value?
> 
> Sometimes the NSTextStorage is created from an empty string, sometimes not. 
> In the case the string is empty, I get the exceptions. If the string is not 
> empty, I don't get the exceptions. A single whitespace character in the 
> string is enough to stop the exceptions.
> 
> Martin
> 
>> 
>> _______________________________________________
>> 
>> Cocoa-dev mailing list ([email protected])
>> 
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>> 
>> Help/Unsubscribe/Update your Subscription:
>> http://lists.apple.com/mailman/options/cocoa-dev/martin.hewitson%40aei.mpg.de
>> 
>> This email sent to [email protected]
> 
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Martin Hewitson
> Albert-Einstein-Institut
> Max-Planck-Institut fuer 
>    Gravitationsphysik und Universitaet Hannover
> Callinstr. 38, 30167 Hannover, Germany
> Tel: +49-511-762-17121, Fax: +49-511-762-5861
> E-Mail: [email protected]
> WWW: http://www.aei.mpg.de/~hewitson
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> 
> 
> 
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Martin Hewitson
Albert-Einstein-Institut
Max-Planck-Institut fuer 
    Gravitationsphysik und Universitaet Hannover
Callinstr. 38, 30167 Hannover, Germany
Tel: +49-511-762-17121, Fax: +49-511-762-5861
E-Mail: [email protected]
WWW: http://www.aei.mpg.de/~hewitson
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~





_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to