Re: Adding attributes to text in a text table cell
Re: Adding attributes to text in a text table cell
- Subject: Re: Adding attributes to text in a text table cell
- From: Charles Jenkins <email@hidden>
- Date: Fri, 21 Nov 2014 08:23:54 -0500
You are soooo right, Ken. Instead of using an attributes property, I now have a function:
-(NSDictionary*)mergeAttributes:(NSDictionary*)existingAttributes
I use the enumerateAttributes method you mentioned in an earlier post to iterate over all the different attribute sets in rangeForUserParagraphChange, and the body of my block simply does something like this:
[ts addAtributes:[sty mergeAttributes:attributes] range:range];
That way the attributes are merged as many times as necessary, rather than merging with the attributes at the first character position and then obliterating all else.
Unless I have a bug I haven’t found yet, the new problem this leads to is that inside a table cell, NSTextView’s rangeForUserParagraphChange doesn’t adjust the current selection range to encompass whole paragraphs as expected: instead, it expands to include everything in the cell. My style-changing code works, but it changes too many paragraphs at once.
I think maybe I’m asking for problems by using a giant table to divide up my subdocuments. My next thought is to use a special attachment which draws as a horizontal line. Put one between each subdocument and make sure the user can’t delete/cut/overwrite them.
I got into this because I was originally thinking I needed a separate NSTextView for each subdocument, but I ran into several problems: I couldn’t get a single-column table view to lay them out right; a stack view presented drawing and performance problems; and my friends at my local Cocoaheads group, who are mostly iPhone programmers, were horrified at the thought of a scrollview containing potentially hundreds of separate text views. So now I’m looking for a new approach which will use only one text view, period. Do you have any ideas that might beat the text-table or special-attachment approaches?
—
Charles Jenkins
On Thursday, November 20, 2014 at 17:31, Ken Thomases wrote:
> 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