Re: Solved: NSTextAttachment affecting NSMutableAttributedString attributes
Re: Solved: NSTextAttachment affecting NSMutableAttributedString attributes
- Subject: Re: Solved: NSTextAttachment affecting NSMutableAttributedString attributes
- From: Keith Blount <email@hidden>
- Date: Thu, 17 Nov 2005 14:18:04 -0800 (PST)
Thanks for sharing. That seems a very good solution
that would indeed be less code in most situations.
(Although not in my own: in my app, a single text
storage can appear in various text views that have to
have different delegates, so it is actually less code
in this situation to fix it in the text storage
itself, especially seeing as I have a custom text
storage to do other stuff anyway.)
Glad you managed to fix it,
All the best,
Keith
--- Gordon Worley <email@hidden> wrote:
>
> On Nov 15, 2005, at 2:04 PM, Keith Blount wrote:
>
> > I believe this is a known "bug" in the text
> system. As
> > I understand it, NSMutableAttributedString's
> > -fixAttachmentAttributeInRange: does more than it
> is
> > documented to do - so that it strips *all* text
> > attributes, not just the attachment attributes.
> This
> > is really annoying for precisely the reasons you
> > detail - if an attachment is inserted at the end
> of a
> > text view, for instance, all typing attributes
> that
> > follow will be reset to the default Helvetica 12
> > point.
>
> I ended up solving the problem this way:
>
> - (NSDictionary *)textView:(NSTextView *)textView
> shouldChangeTypingAttributes:(NSDictionary
> *)oldTypingAttributes
> toAttributes:(NSDictionary *)newTypingAttributes
> {
> if ([newTypingAttributes objectForKey:
> NSAttachmentAttributeName])
> {
> NSMutableDictionary *fixedNew =
> [NSMutableDictionary
> dictionaryWithDictionary: newTypingAttributes];
> [fixedNew addEntriesFromDictionary:
> oldTypingAttributes];
> return fixedNew;
> }
> }
>
> This works since when newTypingAttributes contains
> an
> NSAttachmentAttributeName keyed object, this is the
> only thing it
> contains (all part of the bug in the system). Just
> setting typing
> attributes manually still failed. Not quite is cool
> as fixing the
> broken object directly, but it works and takes a lot
> less code.
>
> -- -- -- -- -- -- -- -- -- -- -- -- -- --
> Gordon Worley
> Phone: 352-875-5808
> e-mail: email@hidden PGP: 0xBBD3B003
> Web: http://homepage.mac.com/redbird/
>
>
__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden