Just a quick update, as I've played with this some more: I have tried passing 
in various ranges to -checkTextInRange:types:options:, thinking that maybe it 
needed a typing range (of 1 in length), and trying to emulate the sorts of 
ranges that get passed into the method by the text view (by overriding and 
NSLogging to check the sort of ranges passed in); I've also tried specifying 
the types (e.g. NSTextCheckingTypeReplacement and NSTextCheckingAllSystemTypes) 
rather than relying on -enabledTextCheckingTypes and passing different things 
into the options dictionary (which shouldn't be necessary), all to no avail. 
For now kludging it with -checkTextInSelection: works, but I'd still love to 
know how to use the -checkTextInRange:types:options: method if anyone has any 
ideas...

Thanks and all the best,
Keith

-- Original message --

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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to