• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Font resets to Lucida Grande when using lists in NSTextView [workaround]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Font resets to Lucida Grande when using lists in NSTextView [workaround]


  • Subject: Font resets to Lucida Grande when using lists in NSTextView [workaround]
  • From: Philip Dow <email@hidden>
  • Date: Thu, 15 Mar 2007 12:01:11 +0100

Hi all, for posterity...

I've encountered a semi-reproducible problem using certain fonts with lists in NSTextView. Newlining to produce another item in the list or tabbing to change the indentation can reset the current font to Lucida Grande. This doesn't seem to happen with all fonts, but it can happen with the common ones, ie Georgia Italic. TextEdit also suffers from the bug.

To reproduce: type something in a text view. Change the font to, for example, Georgia Italic. Make a list out of the text. Hit return to create a new item in the list. Tab to indent. Type. Create a new item. Type. By now the font should have been reset to Lucida Grande. If not, fool around a bit by creating new items in the list, deleting them and changing the indent. At some point the font will reset.

Apple Bug Report #5065130

The Workaround: Subclass NSTextView and override setTypingAttributes: to check for the presence of lists and the tab character. Use the current font when necessary. If someone has a cleaner workaround, I'm interested, as this is a bit of a hack.

- (void)setTypingAttributes:(NSDictionary *)attributes
{
// a fix for the re-set typing attributes problem when new-lining or tabbing during lists


BOOL overrideAttributes = NO;
NSParagraphStyle *paragraphStyle = [attributes objectForKey:NSParagraphStyleAttributeName];


if ( paragraphStyle != nil )
{
NSArray *textLists = [paragraphStyle textLists];
if ( [textLists count] != 0 )
{
NSRange theSelectionRange = [self selectedRange];
if ( theSelectionRange.location >= 1 )
{
unichar aChar = [[self string] characterAtIndex:theSelectionRange.location-1];
if ( aChar == NSTabCharacter ) // -- and it seems to always be the case for the bug we're dealing with
{
NSFont *previousFont = [[self typingAttributes] objectForKey:NSFontAttributeName];
if ( previousFont != nil )
{
overrideAttributes = YES;
NSMutableDictionary *betterAttributes = [[attributes mutableCopyWithZone:[self zone]] autorelease];
[betterAttributes setObject:previousFont forKey:NSFontAttributeName];
[super setTypingAttributes:betterAttributes];
}
}
}
}
}


if ( overrideAttributes == NO )
[super setTypingAttributes:attributes];
}

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


  • Prev by Date: Ping: Look for hints for "nested transaction" problem with Core Data
  • Next by Date: Re: Getting colour data at specified point in an NSImage
  • Previous by thread: NSImage save error
  • Next by thread: NSBezierPath & Metric measurements
  • Index(es):
    • Date
    • Thread