コード例 #1
0
        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);
        }
コード例 #2
0
            public DiffPieceGroup(DiffPieceGroup previous, ChangeType type)
            {
                Previous = previous;
                if (previous != null)
                {
                    previous.Next = this;
                }

                Lines = new List <DiffPiece> ();
                Type  = type;
            }