Re: NSSpellChecker and checkSpellingOfString problems
Re: NSSpellChecker and checkSpellingOfString problems
- Subject: Re: NSSpellChecker and checkSpellingOfString problems
- From: Keith Blount <email@hidden>
- Date: Fri, 4 Dec 2009 01:29:53 -0800 (PST)
Just an update on this. It seems to be a Snow Leopard bug, as I can now reproduce it in TextEdit. If you try typing "accede" or "accademia" in an empty TextEdit window, then ctrl-click on them to get suggestions, you get nothing - they aren't caught as misspelled. If you do the same when the misspelled word is at the end of the line, you get suggestions. But I tried it on Tiger and everything works fine there. Off to file a bug report with Apple. :(
---
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