[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSAttributedString (AppKit) small bug

From: Ludovic Marcotte
Subject: NSAttributedString (AppKit) small bug
Date: Wed, 28 Nov 2001 15:18:42 -0500 (EST)


I think there is a small bug in NSAttributedString (AppKit): 
- (void) fixParagraphStyleAttributeInRange: (NSRange)range.

For example, if you have a NSTextAttachment as the first character of
a line in your NSAttributedString like this:

this is

Use Ink.app (or GNUMail.app) and type in a NSTextView:

this is

Then, you put your cursor position right after the 'a' and insert
a new line like this:

this is
       <- blank line, cursor position here

Then, insert your text attachment. Move your cursor to the next line,
just before the first letter 't' and try to type. You'll enter in an
infinite loop.

This is due to the fact that style is nil for the NSTextAttachment. We
then try to set the loc to NSMaxRange(found) but, NSMaxRange(found)
is equal to loc so we we'll loop infinitely.

NSMaxRange(found) is equal to loc because when we do:

 style = [self attribute: NSParagraphStyleAttributeName
                    atIndex: r.location
                    longestEffectiveRange: &found
                    inRange: r];

found will have a length of 1 and r.location points to the 
character which doesn't have the NSParagraphStyleAttributeName attribute.

so NSMaxRange(found) == loc.

I propose that we add an extra condition like this:

     if (style != nil && NSMaxRange (found) < end)
      // extra condition
      else if (style == nil)
          loc = NSMaxRange (found) + 1;
      // end of extra condition
          loc = NSMaxRange (found);     

This will prevent the infinite loop since we will 'skip' that part
of the text (when the style is nil).

Thanks a lot,

Live as if you were to die tomorrow.
Learn as if you were to live forever.
 - Gandhi

reply via email to

[Prev in Thread] Current Thread [Next in Thread]