I have a class that inherits from NSTextView, which, when initialized, sets up auto spell checking with
setContinuousSpellCheckingEnabled(true)
makeFirstResponder()
setContinuousSpellCheckingEnabled()
setSpellingState
When using setSpellingState
, the squiggly line would sometimes appear and immediately disappear because of a race condition between setSpellingState
and the auto spell-checker. It seems like if they both tried to highlight a word at the same time, they would cancel each other out. Since the auto spell checker's behavior is what's causing this whole problem in the first place, I just replaced setContinuousSpellCheckingEnabled(true)
with setContinuousSpellCheckingEnabled(false)
, and now the red squiggle underline appears correctly, no matter how I type the word! As long as it's misspelled of course :)
For anyone having issues with NSTextView's auto spell checker, I was able to simply disable the auto spell checker using setContinuousSpellCheckingEnabled(false)
, and hacking in my own automatic spell checker using NSSpellChecker.shared()
to check for misspelled words, and setSpellingState
to force-draw the red squiggly spelling indicator under the misspelled words founds by the NSSpellChecker
. All this was done within the implementation of textViewDidChangeSelection
, so that words could be checked every time the selection was changed by either typing, moving the cursor from an incomplete word, or pasting text.