• 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
Re: Adding attributes to text in a text table cell
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Adding attributes to text in a text table cell


  • Subject: Re: Adding attributes to text in a text table cell
  • From: Ken Thomases <email@hidden>
  • Date: Thu, 20 Nov 2014 16:31:50 -0600

On Nov 20, 2014, at 3:47 PM, Charles Jenkins <email@hidden> wrote:

> I have an NSTextTable in which each cell will contain the entire text of a small RTF document. I want the user to be able to edit the document’s text in the cell, including applying styles.
>
> In this case, a “style" means an NSDictionary containing entries for NSFontAttributeName, NSParagraphStyleAttributeName, and some custom attributes that I need, but I think the layout manager will ignore.
>
> When I go to apply a style to a paragraph, I call this method in my subclass of NSTextView:
>
> -(void)setParagraphStyle:(NSString*)styleName
> {
>  Document* doc = [[self.window windowController] document];
>  NamedStyle* sty = [doc.styleSet styleByName:styleName];
>
>  [self.textStorage addAttributes:sty.attributes
>                            range:self.rangeForUserParagraphAttributeChange];
>
>  [self didChangeText];
> }
>
>
> Okay, I know that must be very wrong, because although doing it does alter the text as I expect, it also blows up my text table and breaks or merges cells.
>
> What should I be doing instead, rather than blithely calling addAttributes:range:?

The table-ness of text is stored in the paragraph style.  You are replacing the paragraph style.  -addAttributes:range: will preserve existing attributes _other than any you specify_.  It will replace the value for any attributes you specify.  You are presumably specifying a value for NSParagraphStyleAttributeName, so you are replacing the paragraph style.

You need to manually merge the existing paragraph style with the one in sty.attributes.  For the table-ness in particular, you need to figure out which elements of the existing textBlocks array are for the enclosing table and keep those, then append any textBlocks from the new style you want to apply (if any).  From the sound of it, you only expect a single enclosing table, so you would only keep the first element of the existing textBlocks array.

Regards,
Ken


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Adding attributes to text in a text table cell
      • From: Charles Jenkins <email@hidden>
References: 
 >Adding attributes to text in a text table cell (From: Charles Jenkins <email@hidden>)

  • Prev by Date: Re: how to reset another app's prefs
  • Next by Date: Re: Making the Versions Browser less of a dog
  • Previous by thread: Adding attributes to text in a text table cell
  • Next by thread: Re: Adding attributes to text in a text table cell
  • Index(es):
    • Date
    • Thread