How to use NSTextView's new -checkTextInRange:types:options:?
How to use NSTextView's new -checkTextInRange:types:options:?
- Subject: How to use NSTextView's new -checkTextInRange:types:options:?
- From: Keith Blount <email@hidden>
- Date: Mon, 31 Aug 2009 07:22:20 -0700 (PDT)
Hello,
I am trying to force text checking in an NSTextView on Snow Leopard using the new -checkTextInRange:types:options: method, but I can't seem to get this method to work at all. I am aware that the documentation clearly states that "this method *usually* would not be called directly" (although it does not say "never" or "should not be") as NSTextView calls it from its various text checking methods automatically, but my text view subclass adds other types of substitutions which mean I need to force text checking on the built-in types either before or after making my custom substitutions. (For instance, I have an auto-capitalisation method that gets called in -textDidChange:. If auto-capitalisation alters a word that is in the system "substitutions" list, though, it prevents substitutions from happening, presumably because the changed range gets affected before the substitutions code gets called. Therefore in the situation where auto-caps is going to change
the text, I need to force text checking beforehand.)
The -checkTextInRange:types:options: method doesn't seem to work as expected, though, presumably because the documentation is new and doesn't explain it properly as yet. For instance, I would expect this:
// (Note that "self" here is an NSTextView subclass.)
[self checkTextInRange:NSMakeRange(0,[[self textStorage] length]) types:[self enabledTextCheckingTypes] options:nil];
to have the same effect as this:
[self checkTextInDocument:nil];
or this:
[self setSelectedRange:NSMakeRange(0,[[self textStorage] length])];
[self checkTextInSelection:nil];
But it doesn't. Both of the latter methods - the action methods - work as expected, checking and replacing the text where necessary - but the code using -checkTextInRange:types:options: directly apparently does nothing at all - no text gets replaced. (Even though the docs clearly describe the method thus: "Check and replace the text in the range using the specified checking types and options.")
(Note: [self enabledTextCheckingTypes] is not 0 - it includes quotes and text replacement etc; hence the two action methods work. So I'm not doing anything as silly as passing the method no checking types.)
I can get my auto-caps to work with the new substitution methods if I just use -checkTextInSelection:, setting the selection before calling it and resetting the selection immediately afterwards, but this is a bit of a kludge and I would rather use the -checkTextInRange:... method directly if at all possible.
Has anybody tried this new method, encountered similar problems or found a solution? Is there something I need to do in conjunction with this method to get it working?
Many thanks in advance and all the best,
Keith
_______________________________________________
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