Re: NSSpellChecker and checkSpellingOfString problems (solved... embarrassingly)
Re: NSSpellChecker and checkSpellingOfString problems (solved... embarrassingly)
- Subject: Re: NSSpellChecker and checkSpellingOfString problems (solved... embarrassingly)
- From: Keith Blount <email@hidden>
- Date: Fri, 4 Dec 2009 01:42:25 -0800 (PST)
Please ignore all previous messages about NSSpellChecker. I wish there were a way to withdraw mails after they've been sent, because it turns out I'm an idiot.
This is actually a *feature* of Snow Leopard, not a bug. The misspelled words I was using and that my user had sent me were all fine in a different language; and because the spell-checker was set to "Automatic by Language" (not English as I had thought and said here), it wasn't reporting a problem until there were more English words. Had I a better (or any grasp) of Italian I might have realised this earlier.
Sorry for wasting your time.
Best,
Keith
---
Hello,
I have an NSTextView subclass that provides a custom contextual menu by overriding -menuForEvent:. Because I override this, I have to provide any menu items I want to retain from the original menu myself. Mostly, that's not a problem, but I want to keep the spell checking options at the top of the menu as well. I thought I had this covered. This is what I'm doing:
// Is there a selection?
if (selRange.length > 0 && selRange.location < [text length])
{
// If so, check to see if the selected range constitutes a misspelled word.
NSSpellChecker *spellChecker = [NSSpellChecker sharedSpellChecker];
NSRange misspelledRange = [spellChecker checkSpellingOfString:[[text string] substringWithRange:selRange] startingAt:0];
// Detected misspelled word?
if (misspelledRange.length == selRange.length)
{
// Get suggestions.
NSArray *suggestions = [spellChecker guessesForWord:[[text string] substringWithRange:selRange]];
// Are there any suggestions?
if ([suggestions count] > 0)
{
// If so, add them to the menu with an appropriate action.
}
else
{
// Otherwise insert the "No Guesses Found" item.
}
}
I thought all of this was working fine. However, a user has just pointed out to me that it doesn't work for all misspellings... Which is very strange. The problem comes down to NSSpellChecker's -checkSpellingOfString:. This returns an NSNotFound range for certain misspellings.
For instance:
Try typing "accade" into TextEdit (I'm assuming English as the language here, of course). It is underlined in red, and ctrl-clicking on it brings up a list of suggestions. So the system recognises it as a misspelling, a word that it doesn't know.
Now try this in any test app:
NSRange range = [[NSSpellChecker sharedSpellChecker] checkSpellingOfString:@"accade" startingAt:0];
NSLog (@"NSStringFromRange(range));
range will be (NSNotFound,0).
I don't understand why, though. Why isn't NSSpellChecker returning this as a misspelling? Am I missing something obvious? Is there a better way to insert the spelling suggestions at the top of the menu?
Thanks 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