protected virtual SpanBuilder UpdateSpan(Span target, TextChange normalizedChange) { var newContent = normalizedChange.ApplyChange(target); var newSpan = new SpanBuilder(target); newSpan.ClearSymbols(); foreach (ISymbol sym in Tokenizer(newContent)) { sym.OffsetStart(target.Start); newSpan.Accept(sym); } if (target.Next != null) { var newEnd = SourceLocationTracker.CalculateNewLocation(target.Start, newContent); target.Next.ChangeStart(newEnd); } return newSpan; }
private PartialParseResult TryAcceptChange(Span target, TextChange change, PartialParseResult acceptResult = PartialParseResult.Accepted) { var content = change.ApplyChange(target); if (StartsWithKeyword(content)) { return PartialParseResult.Rejected | PartialParseResult.SpanContextChanged; } return acceptResult; }
public void ApplyChangeWithReplacedTextReturnsNewContentWithChangeApplied() { // Arrange var newBuffer = new StringTextBuffer("abcdefg"); var oldBuffer = new StringTextBuffer(""); var textChange = new TextChange(1, 1, oldBuffer, 2, newBuffer); // Act string text = textChange.ApplyChange("abcdefg", 1); // Assert Assert.Equal("bcbcdefg", text); }
public void ApplyChangeWithInsertedTextReturnsNewContentWithChangeApplied() { // Arrange var newBuffer = new StringTextBuffer("test"); var oldBuffer = new StringTextBuffer(""); var textChange = new TextChange(0, 0, oldBuffer, 3, newBuffer); // Act string text = textChange.ApplyChange("abcd", 0); // Assert Assert.Equal("tesabcd", text); }