/// <summary> /// Determines the type of character that is currently pointed to by _offset, /// </summary> /// <param name="charsToConsume"></param> /// <returns></returns> private CharClass ClassifyChar(string strval, int offset, out int charsToConsume) { charsToConsume = 1; char currChar = strval[offset]; if (currChar == '&') { int nextSemi = strval.IndexOf(';', offset + 1); if (nextSemi != -1) { int code = HtmlUtils.DecodeEntityReference(strval.Substring(offset + 1, nextSemi - offset - 1)); if (code != -1) { charsToConsume = nextSemi - offset + 1; currChar = (char)code; } } } return (!WordRangeHelper.IsNonSymbolChar(currChar) ? CharClass.Break : char.IsLetter(currChar) ? CharClass.Letter : char.IsNumber(currChar) ? CharClass.Number : currChar == '\'' ? CharClass.BoundaryBreak : currChar == '’' ? CharClass.BoundaryBreak : currChar == '.' ? CharClass.IncludedBreakChar : CharClass.Break); }
//takes one the first word on the range, and checks it for spelling errors //***returns true if word is misspelled*** private bool ProcessWord(MshtmlWordRange word, out int offset, out int length) { offset = 0; length = 0; string otherWord = null; SpellCheckResult result; string currentWord = word.CurrentWord; if (!word.IsCurrentWordUrlPart() && !WordRangeHelper.ContainsOnlySymbols(currentWord)) { result = _spellingChecker.CheckWord(currentWord, out otherWord, out offset, out length); } else { result = SpellCheckResult.Correct; } if (result != SpellCheckResult.Correct) { //note: currently using this to not show any errors in smart content, since the fix isn't // propagated to the underlying data structure if (!word.FilterApplies()) { return(true); } } return(false); }
/// <summary> /// Continue the spell-checking loop /// </summary> private void ContinueSpellCheck() { // provide feedback (pump events so underlying control has an // opportunity to update its display) RemoveHighlight(); Application.DoEvents(); if (!spellingChecker.IsInitialized) { Trace.Fail("Spellchecker was uninitialized in the middle of spellchecking after removing highlight."); return; } using (new WaitCursor()) { // loop through all of the words in the word-range bool currentWordMisspelled = false; while (wordRange.HasNext()) { // advance to the next word wordRange.Next(); // check the spelling string otherWord = null; offset = 0; length = wordRange.CurrentWord.Length; SpellCheckResult result; string CurrentWord = wordRange.CurrentWord; if (!wordRange.IsCurrentWordUrlPart() && !WordRangeHelper.ContainsOnlySymbols(CurrentWord)) { result = spellingChecker.CheckWord(CurrentWord, out otherWord, out offset, out length); } else { result = SpellCheckResult.Correct; } //note: currently using this to not show any errors in smart content, since the fix isn't // propogated to the underlying data structure if (result != SpellCheckResult.Correct && !wordRange.FilterAppliesRanged(offset, length)) { // auto-replace if (result == SpellCheckResult.AutoReplace) { // replace word and continue loop (pump events so the document // is updated w/ the new word) wordRange.Replace(offset, length, otherWord); Application.DoEvents(); if (!spellingChecker.IsInitialized) { Trace.Fail("Spellchecker was uninitialized in the middle of spellchecking after auto-replace."); return; } } // some other incorrect word else if (result != SpellCheckResult.Correct) { string misspelledWord = wordRange.CurrentWord; if (offset > 0 && offset <= misspelledWord.Length) { misspelledWord = misspelledWord.Substring(offset); } if (length < misspelledWord.Length) { misspelledWord = misspelledWord.Substring(0, length); } // highlight the misspelled word HighlightWordRange(); // set current misspelled word labelWord.Text = misspelledWord; // misspelling or incorrect capitalization if (result == SpellCheckResult.Misspelled) { labelNotInDictionary.Text = NOT_IN_DICTIONARY; ProvideSuggestions(misspelledWord); } else if (result == SpellCheckResult.Capitalization) { labelNotInDictionary.Text = CAPITALIZATION; ProvideSuggestions(misspelledWord, 1); } // conditional replace else if (result == SpellCheckResult.ConditionalReplace) { labelNotInDictionary.Text = NOT_IN_DICTIONARY; ProvideConditionalReplaceSuggestion(otherWord); } // update state and break out of the loop currentWordMisspelled = true; break; } } } // there is a pending misspelling, make sure the form is visible if (currentWordMisspelled) { EnsureFormVisible(); } // current word not misspelled and no more words, spell check is finished else if (!wordRange.HasNext()) { completed = true; EndSpellCheck(); } } }