public DiffRenderer(string oldText, string newText, int maxContextLines = 3, int tabWidth = 8) { this.maxContextLines = maxContextLines; var inlineBuilder = new InlineDiffBuilder(new Differ()); var diff = inlineBuilder.BuildDiffModel(oldText, newText); int maxLineNumber = 0; DiffPieceGroup currentGroup = null; foreach (var line in diff.Lines) { if (currentGroup == null || currentGroup.Type != line.Type) { currentGroup = new DiffPieceGroup(currentGroup, line.Type); if (FirstGroup == null) { FirstGroup = currentGroup; } } if (line.Position != null) { maxLineNumber = Math.Max(maxLineNumber, line.Position.Value); } maxLineWidth = Math.Max(maxLineWidth, GetLineWidth(line.Text, tabWidth)); currentGroup.Lines.Add(line); } maxLineNumberDigits = (int)Math.Floor(Math.Log10(maxLineNumber) + 1); }
public DiffPieceGroup(DiffPieceGroup previous, ChangeType type) { Previous = previous; if (previous != null) { previous.Next = this; } Lines = new List <DiffPiece> (); Type = type; }