Re: Best way to modify user input into NSTextView
Re: Best way to modify user input into NSTextView
- Subject: Re: Best way to modify user input into NSTextView
- From: Kirk Swenson <email@hidden>
- Date: Tue, 31 Mar 2009 14:35:50 -0700
On Mar 31, 2009, at 8:12 AM, email@hidden wrote:
From: Zac Samuel <email@hidden>
Date: March 31, 2009 3:47:26 AM PDT
To: email@hidden
Subject: Best way to modify user input into NSTextView
I'd like to override the behavior of an NSTextView so that when a
certain
character is typed, a different character is inserted. For example
I'd like
"×" to be inserted when the user types "*". This can be done really
easily
using the shouldChangeTextInRanges:replacementStrings delegate method:
...
However I don't feel like this is the way to go. It seems to be that
these
delegate methods should only be for preventing user input in certain
circumstances, not for actually inserting or adding text. For a
start this
approach seems to disrupt the way NSTextView handles undos, and if an
NSTextAttachment were to be inserted instead of plain text, the
layout of
the view will not update.
Can anyone suggest the "correct" way of doing such modify user input
into
NSTextViews?
I don't know about "correct," but I've done something similar in a
derived class of NSTextField by overriding insertText:, testing for
the string to be replaced, and then passing the replacement string to
[super insertText:]. Of course, to use this approach you have to
implement windowWillReturnFieldEditor:toObject: in your window
controller to return your derived class when asked.
Kirk Swenson
KCP Technologies
_______________________________________________
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