public void Init(VersionInstance content) { Content = content; LexController controller = new LexController(Content.Text, new InitTokenPush(Tokens)); controller.Match(); }
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 IncrementInfo Update(VersionInstance newContent, UpdateRange updateRange) { int 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); } } var tokenInsert = new IncrementalTokenInsert(Tokens, affectedArea.StartingTokenIndex, affectedArea.EndingTokenIndex); LexController controller = new LexController(newContent.Text, tokenInsert); // Set start range controller.Index = affectedArea.StartIndex; controller.Line = newContent.GetLine(controller.Index); controller.Column = newContent.GetColumn(controller.Index); controller.Match(); Content = newContent; return(new IncrementInfo(affectedArea.StartingTokenIndex, affectedArea.EndingTokenIndex, Tokens.Count - lastTokenCount)); }
public void Init(VersionInstance content) { Content = content; CurrentController = new LexController(Content.Text, _currentTokenPush = new InitTokenPush(this)); }