Beispiel #1
0
        public override ITextSegmentStyled FindStyledTextSegment(ITextEditor textEditor, ITextSegment textSegment, ITextDocument document, int index, int length, int textColumnIndex)
        {
            // TODO: This is way too slow. Should be able to speed up significantly.
            foreach (var textView in document.GetTextViews())
            {
                this._cultureInfo = textView.Language;

                if (this._cultureInfo != null)
                {
                    break;
                }
            }

            if (textEditor.Settings.SpellcheckEnabled(this._cultureInfo) == false || textEditor.Settings.InlineEnabled == false)
            {
                return(null);
            }

            var searchStartIndex = textSegment.Index + index;
            var selectedWord     = document.GetWord(searchStartIndex, textSegment, true, textColumnIndex);

            if (selectedWord == null)
            {
                // If the current index has no word, then we exit.
                return(null);
            }

            if (selectedWord.End - selectedWord.Start < 3)
            {
                // If the word is shorter than 3 characters, then we exit.
                return(null);
            }

            if (textEditor.Settings.CheckIfWordIsValid(selectedWord.Word, textSegment.GetText(textColumnIndex)) == false)
            {
                // If the word is not a valid word according to out filter settings, then we exit.
                return(null);
            }

            try
            {
                //var spellcheckValid = ;
                //foreach (var check in LanguageFeature.FeatureFetchMultiple<bool>(this._cultureInfo, "Spellcheck.Check", new LFSString(selectedWord.Word)))
                //{
                //    spellcheckValid = check;
                //    if (spellcheckValid)
                //    {
                //        break;
                //    }
                //}

                if (textEditor.Settings.IsSpelledCorrectly(selectedWord.Word))
                {
                    // If the word is a correctly spelled word, then we exit.
                    return(null);
                }
            }
            catch (Exception)
            {
            }

            // The word is not spelled correctly, so we create a style and return it.
            var incorrectlySpelledTextSegment = document.CreateStyledTextSegment(this);

            incorrectlySpelledTextSegment.Index = selectedWord.Start - textSegment.Index;
            incorrectlySpelledTextSegment.SetLength(textColumnIndex, selectedWord.End - selectedWord.Start);
            incorrectlySpelledTextSegment.Object = selectedWord.Word;

            return(incorrectlySpelledTextSegment);
        }