// // Remove underlining under word. // public bool RemoveUnderliningAt(IUnderlineableSpellingControl editor, int wordCharIndex) { bool result = false; int closestKeyLeft = int.MaxValue; foreach (int key in editor.UnderlinedSections.Keys) { if (wordCharIndex - key >= 0) { closestKeyLeft = key; } else { break; } } CharacterRange curWordRange = NHunspellWrapper.Instance.GetCharRangeFromPosition(editor.SelectionStart); if ((curWordRange.First <= wordCharIndex && wordCharIndex < curWordRange.First + curWordRange.Length) && editor.UnderlinedSections.ContainsKey(curWordRange.First)) { editor.RemoveWordFromUnderliningList(closestKeyLeft); result = true; } return(result); }
// // Update UnderlinedSections variable of the editor. // private void UnderlineIncorrectWords(IUnderlineableSpellingControl editor) { if (editor.IsSpellingAutoEnabled) { UnderlineNewPositionWords(editor, false); //Should Invalidate becasue of no Invalidate called on cursor position changed. editor.Invalidate(true); } backupText = editor.Text; }
// // Update UnderlinedSections variable of the editor, but depending on text changing logic. // Only words that changed it's position are rechecked. // Logic is something that can be always improved. // private void UnderlineNewPositionWords(IUnderlineableSpellingControl editor, bool newPositionWordsOnly) { if (UnderlinableEditor != null && UnderlinableEditor.IsSpellingAutoEnabled) { if (newPositionWordsOnly) { int collapseIndex = findCollapseIndex(backupText, editor.Text); collapseIndex = NHunspellWrapper.Instance.GetCharRangeFromPosition(collapseIndex).First; Dictionary <int, int> tmp = new Dictionary <int, int>(); foreach (int key in editor.UnderlinedSections.Keys) { if (key < collapseIndex) { tmp.Add(key, editor.UnderlinedSections[key]); } } editor.UnderlinedSections = tmp; Dictionary <int, int> newMisspelledWordRanges = NHunspellWrapper.Instance.GetMisspelledWordsRanges(collapseIndex); foreach (int key in newMisspelledWordRanges.Keys) { if (!editor.UnderlinedSections.ContainsKey(key)) { editor.UnderlinedSections.Add(key, newMisspelledWordRanges[key]); } } } else { editor.UnderlinedSections = NHunspellWrapper.Instance.GetMisspelledWordsRanges(); } backupText = UnderlinableEditor.Text; if (UnderliningChanged != null) { UnderliningChanged(); } } }