Beispiel #1
0
        void ReloadDocument(TextDocument document, string newContent)
        {
            var diff = new MyersDiffAlgorithm(new StringSequence(document.Text), new StringSequence(newContent));

            document.Replace(0, document.TextLength, newContent, diff.GetEdits().ToOffsetChangeMap());
            document.UndoStack.ClearAll();
        }
        void SetupInitialFileState(bool update)
        {
            if (baseDocument == null)
            {
                if (update)
                {
                    changeList.Transform(TransformLineChangeInfo);
                }
                else
                {
                    changeList.InsertRange(0, document.LineCount + 1, LineChangeInfo.EMPTY);
                }
            }
            else
            {
                changeList.Clear();

                Dictionary <string, int> hashes = new Dictionary <string, int>();

                MyersDiffAlgorithm diff = new MyersDiffAlgorithm(
                    new DocumentSequence(baseDocument, hashes),
                    new DocumentSequence(document, hashes)
                    );

                changeList.Add(LineChangeInfo.EMPTY);
                int lastEndLine = 0;

                foreach (Edit edit in diff.GetEdits())
                {
                    int beginLine = edit.BeginB;
                    int endLine   = edit.EndB;

                    changeList.InsertRange(changeList.Count, beginLine - lastEndLine, LineChangeInfo.EMPTY);

                    if (endLine == beginLine)
                    {
                        changeList[changeList.Count - 1] = new LineChangeInfo(edit.EditType, edit.BeginA, edit.EndA);
                    }
                    else
                    {
                        changeList.InsertRange(changeList.Count, endLine - beginLine, new LineChangeInfo(edit.EditType, edit.BeginA, edit.EndA));
                    }
                    lastEndLine = endLine;
                }

                changeList.InsertRange(changeList.Count, textDocument.LineCount - lastEndLine, LineChangeInfo.EMPTY);
            }

            OnChangeOccurred(EventArgs.Empty);
        }
Beispiel #3
0
        void ReloadDocument(TextDocument document, string newContent)
        {
            var diff = new MyersDiffAlgorithm(new StringSequence(document.Text), new StringSequence(newContent));

            document.Replace(0, document.TextLength, newContent, diff.GetEdits().ToOffsetChangeMap());

            if (this.ClearUndoStackOnSwitch || documentFirstLoad)
            {
                document.UndoStack.ClearAll();
            }

            if (documentFirstLoad)
            {
                documentFirstLoad = false;
            }
        }
Beispiel #4
0
        public string ToString(int contextLines)
        {
            if (contextLines < 0)
            {
                contextLines = 2;
            }

            StringBuilder sb = new StringBuilder();

            sb.AppendLine();
            foreach (var e in _ma.GetEdits())
            {
                if (e.EditType == ChangeType.None)
                {
                    continue;
                }
                sb.AppendFormat("@@@ -{0},{1} +{2},{3}",
                                1 + Math.Max(0, e.BeginA - contextLines),
                                1 + Math.Min(_b.Size(), e.EndA + contextLines),
                                1 + Math.Max(0, e.BeginB - contextLines),
                                1 + Math.Min(_b.Size(), e.EndB + contextLines));
                sb.AppendLine();
                AppendLines(sb, " ", _a.EnumerateLines(e.BeginA - contextLines, e.BeginA));
                if (e.EditType == ChangeType.Modified)
                {
                    AppendLines(sb, "-", _a.EnumerateLines(e.BeginA, e.EndA));
                    AppendLines(sb, "+", _b.EnumerateLines(e.BeginB, e.EndB));
                    continue;
                }
                else if (e.EditType == ChangeType.Added)
                {
                    AppendLines(sb, "+", _b.EnumerateLines(e.BeginB, e.EndB));
                }
                else if (e.EditType == ChangeType.Deleted)
                {
                    AppendLines(sb, "-", _b.EnumerateLines(e.BeginA, e.EndA));
                }
                AppendLines(sb, " ", _a.EnumerateLines(e.EndA + 1, e.EndA + contextLines));
            }
            return(sb.ToString());
        }