public void MarkTokens(IDocument document) { if (document == null) { throw new ArgumentNullException(nameof(document)); } var tokens = GetHighlightedTokens(document.TextContent); var tokenEnum = tokens.GetEnumerator(); var tokenEnd = !tokenEnum.MoveNext(); foreach (var line in document.LineSegmentCollection) { (line.Words = line.Words ?? new List <TextWord>()).Clear(); var offset = line.Offset; while (!tokenEnd) { if (offset >= line.Offset + line.Length) { break; } var token = tokenEnum.Current; if (token.End <= offset) { tokenEnd = !tokenEnum.MoveNext(); continue; } if (offset < token.Start) { token = new HighlightedSegment <string>(offset, token.Start, null); } var end = Math.Min(line.Offset + line.Length, token.End); line.Words.Add(new TextWord(document, line, offset - line.Offset, end - offset, this.GetColorFor(token.Value), true)); offset = end; } if (offset < line.Offset + line.Length) { line.Words.Add(new TextWord(document, line, offset - line.Offset, line.Offset + line.Length - offset, this.GetColorFor(null), true)); } } document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea)); document.CommitUpdate(); }
public void MarkTokens(IDocument document) { if (document == null) { throw new ArgumentNullException(nameof(document)); } var tokens = GetHighlightedTokens(document.TextContent); var tokenEnum = tokens.GetEnumerator(); var tokenEnd = !tokenEnum.MoveNext(); foreach (var line in document.LineSegmentCollection) { (line.Words = line.Words ?? new List<TextWord>()).Clear(); var offset = line.Offset; while (!tokenEnd) { if (offset >= line.Offset + line.Length) { break; } var token = tokenEnum.Current; if (token.End <= offset) { tokenEnd = !tokenEnum.MoveNext(); continue; } if (offset < token.Start) { token = new HighlightedSegment<string>(offset, token.Start, null); } var end = Math.Min(line.Offset + line.Length, token.End); line.Words.Add(new TextWord(document, line, offset - line.Offset, end - offset, this.GetColorFor(token.Value), true)); offset = end; } if (offset < line.Offset + line.Length) { line.Words.Add(new TextWord(document, line, offset - line.Offset, line.Offset + line.Length - offset, this.GetColorFor(null), true)); } } document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea)); document.CommitUpdate(); }