public void Update(VersionInstance newContent, UpdateRange updateRange) { IsPushCompleted = false; _lastTokenCount = Tokens.Count; AffectedAreaInfo affectedArea = GetAffectedArea(updateRange); // The number of lines int lineDelta = NumberOfNewLines(updateRange.Text) - updateRange.Range.LineSpan(); int columnDelta = NumberOfCharactersInLastLine(updateRange.Text) - updateRange.Range.ColumnSpan(); int indexOffset = updateRange.Text.Length - (Content.IndexOf(updateRange.Range.End) - Content.IndexOf(updateRange.Range.Start)); // Adjust token ranges. for (int i = affectedArea.EndingTokenIndex; i < Tokens.Count; i++) { if (updateRange.Range.End <= Tokens[i].Range.Start) { // Use the old content for getting the update range index. int s = Content.IndexOf(Tokens[i].Range.Start) + indexOffset, e = Content.IndexOf(Tokens[i].Range.End) + indexOffset; // Use the new content to update the positions. newContent.UpdatePosition(Tokens[i].Range.Start, s); newContent.UpdatePosition(Tokens[i].Range.End, e); } } _currentTokenPush = new IncrementalTokenInsert(this, affectedArea.StartingTokenIndex, affectedArea.EndingTokenIndex); CurrentController = new LexController(newContent.Text, _currentTokenPush); // Set start range CurrentController.Index = affectedArea.StartIndex; CurrentController.Line = newContent.GetLine(CurrentController.Index); CurrentController.Column = newContent.GetColumn(CurrentController.Index); Content = newContent; IncrementalChangeStart = affectedArea.StartingTokenIndex; IncrementalChangeEnd = affectedArea.EndingTokenIndex; }
public void Init(VersionInstance content) { Content = content; CurrentController = new LexController(Content.Text, _currentTokenPush = new InitTokenPush(this)); }
public LexController(string content, ITokenPush push) { Content = content; _push = push; }