Re: NSTextView and limiting text attributes via delegate
Re: NSTextView and limiting text attributes via delegate
- Subject: Re: NSTextView and limiting text attributes via delegate
- From: Scott Lehman <email@hidden>
- Date: Sat, 4 Feb 2006 14:14:33 -0800 (PST)
I opted to try a custom text storage subclass since it
seemed like a centralized way to filter out unwanted
attributes.
Is there any particular reason to override the
fixAttributes method versus the setAttributes:range:?
In my testing, I do see that the former seems to be
called just once for a range containing differing
attributes unlike the latter, but I would have to
divide it into the different attribute runs anyway.
Thanks,
Scott
--- Douglas Davidson <email@hidden> wrote:
>
> On Feb 3, 2006, at 3:01 PM, Scott Lehman wrote:
>
> > I have an NSTextView, but want to limit the kinds
> of
> > formatting that can be used in it. The new
> delegate
> > method
> >
> textView:shouldChangeTypingAttributes:toAttributes:
> > caught my eye as a good place to start, however it
> > doesn't seem to do what I expect.
> >
>
> The typing attributes are the attributes that will
> be used for the
> next character that is typed. Try bringing up an
> empty document in
> TextEdit, hitting cmd-U, and typing something; it
> should appear
> underlined. Your implementation of the delegate
> method should be
> able to prevent that.
>
> However, you also want to control changes to the
> text. You can use
> textView:shouldChangeTextInRange:replacementString:
> to be notified of
> this. Try making a note of the range in this
> method--modifying its
> length based on the replacement string's if there is
> one--and then in
> textDidChange: you can examine the changed text and
> remove any
> unwanted attributes.
>
> Another alternative would be to use a custom text
> storage, not to
> change the storage mechanism, but to override
> attribute fixing.
> Working at the text view delegate level lets you
> control user-
> initiated changes. At the text storage level, you
> can modify all
> changes, programmatic or user-driven.
>
> Douglas Davidson
>
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
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