public override ITextSegmentStyled FindStyledTextSegment(ITextEditor textEditor, ITextSegment textSegment, ITextDocument document, int index, int length, int textColumnIndex) { var lineIndex = document.GetLineFromCharIndex(textSegment.Index + index, textColumnIndex); var firstCharIndex = document.GetFirstCharIndexFromLine(lineIndex); var styleCount = document.TextSegmentStyledManager.Get(firstCharIndex, NameKey, textColumnIndex).Count(); if (styleCount > 0) { return(null); } var content = document.GetLineText(lineIndex, textColumnIndex); var isManual = _regexManual.IsMatch(content); // Regex.IsMatch(content, "^\\d:"); var isSwitch = _regexSwitch.IsMatch(content); // Regex.IsMatch(content, "^-[^\\-]"); if (isManual || isSwitch) { var segment = document.CreateStyledTextSegment(this); segment.Index = 0; segment.SetLength(textColumnIndex, 1); segment.Object = isManual ? int.Parse("" + document.GetCharFromIndex(firstCharIndex, textColumnIndex)) : -1; return(segment); } if (content.StartsWith("[")) { var match = _regexTimestamp.Match(content); if (match.Success) { if (string.IsNullOrEmpty(match.Groups[3].Value) == false) { var segment = document.CreateStyledTextSegment(this); segment.Index = 0; segment.SetLength(textColumnIndex, content.Length); segment.Object = -2; return(segment); } } } return(null); }
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); }
public override ITextSegmentStyled FindStyledTextSegment(ITextEditor textEditor, ITextSegment textSegment, ITextDocument document, int startIndex, int length, int textColumnIndex) { var text = textSegment.GetText(textColumnIndex); if (startIndex >= text.Length) { return(null); } foreach (var word in this.WordList) { for (var i = 0; i < word.Length; i++) { if (word[i] != text[startIndex]) { continue; } var found = true; var left = i - 1; for (; left >= 0; left--) { var relativeIndex = startIndex - (i - left); if (relativeIndex < 0) { found = false; break; } var c = text[relativeIndex]; if (word[left] != c) { found = false; break; } } if (found == false) { break; } left = Math.Max(0, left); var right = i + 1; for (; right < word.Length; right++) { var relativeIndex = startIndex + (right - i); if (relativeIndex >= text.Length) { found = false; break; } var c = text[relativeIndex]; if (word[right] != c) { found = false; break; } } if (found) { var newTextSegment = document.CreateStyledTextSegment(this); var relativeIndex = startIndex - (i - left); newTextSegment.Index = relativeIndex; newTextSegment.SetLength(textColumnIndex, right - left); newTextSegment.Object = word; return(newTextSegment); } } } return(null); }