Re: NSTextView insertText & undo
Re: NSTextView insertText & undo
- Subject: Re: NSTextView insertText & undo
- From: Glen Simmons <email@hidden>
- Date: Thu, 26 May 2005 18:59:55 -0500
On May 26, 2005, at 5:07 PM, Douglas Davidson wrote:
On May 26, 2005, at 2:58 PM, Glen Simmons wrote: I'm "translating" keys that are entered in an NSTextView subclass into images by: 1. catching the key in -[MyTextView keyDown:] 2. creating an NSAttributedString with an NSTextAttachment 3. calling: [myTextView shouldChangeTextInRange:[myTextView rangeForUserTextChange] replacementString:nil] [myTextView insertText:theAttrStr]; [myTextView didChangeText];
This doesn't sound quite right. First, insertText: is the funnel point for user typing of characters; it does shouldChangeText... itself. Second, if you are actually inserting or deleting text, the replacement string should not be nil; a nil replacement string is for attribute changes. Third, you probably don't want to catch this at keyDown:, unless you really are defining the keys that you are looking for in terms of raw key strokes.
What keys are you catching, and what is the goal here?
Well, the requirement I have is to translate a particular set of characters into images and not allow any other characters. I don't really care where I catch them, I just need to change what gets inserted and disallow other characters. I think I was passing nil for the replacement string because I'm not actually inserting a string, I'm inserting the NSAttributedString/NSTextAttachment thing and -shouldChangeTextInRange:replacementString: takes an NSString. How should this be done so that it works nicely with keyboard entry, paste and undo?
Thanks, Glen |
_______________________________________________
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