public void TestDeleteLineWithConflicts() { TextFileInformation tfi = new TextFileInformation(); tfi.NewGenFile = new TextFile("line 0\r\nline 12\r\nline 2"); tfi.UserFile = new TextFile("line 0\r\nline 13\r\nline 2"); tfi.PrevGenFile = new TextFile("line 0\r\nline 1\r\nline 2"); tfi.IntelliMerge = IntelliMergeType.PlainText; tfi.RelativeFilePath = "text.txt"; ThreeWayVisualDiff diffUtility = new ThreeWayVisualDiff(tfi); VisualDiffOutput output = diffUtility.ProcessMergeOutput(); Assert.IsNotNull(output); Assert.That(output.RightLines, Has.Count(4)); Assert.That(output.LeftLines, Has.Count(4)); output.RemoveLine(0); Assert.That(output.RightLines, Has.Count(3)); Assert.That(output.LeftLines, Has.Count(3)); Assert.That(output.LeftLines[0].Text, Is.EqualTo("line 13")); Assert.That(output.RightLines[0].Text, Is.EqualTo("")); Assert.That(output.RightLines[0].IsVirtual, Is.EqualTo(true)); Assert.That(output.ConflictRanges[0].StartLineIndex, Is.EqualTo(0)); Assert.That(output.ConflictRanges[0].EndLineIndex, Is.EqualTo(2)); }
public void TestTemplateChange_Delete_At_End() { TextFileInformation tfi = new TextFileInformation(); tfi.PrevGenFile = tfi.UserFile = new TextFile("line1\nline2"); tfi.NewGenFile = new TextFile("line1"); tfi.IntelliMerge = IntelliMergeType.PlainText; tfi.RelativeFilePath = "text.txt"; ThreeWayVisualDiff diffUtility = new ThreeWayVisualDiff(tfi); VisualDiffOutput output = diffUtility.ProcessMergeOutput(); Assert.IsNotNull(output); Assert.That(output.RightLines, Is.Not.Empty); Assert.That(output.LeftLines, Is.Not.Empty); Assert.That(output.LeftLines, Has.Count(2)); Assert.That(output.RightLines, Has.Count(2)); Assert.That(output.LeftLines[0].Text, Is.EqualTo("line1")); Assert.That(output.LeftLines[1].Text, Is.EqualTo("line2")); Assert.That(output.RightLines[0].Text, Is.EqualTo("line1")); Assert.That(output.RightLines[1].Text, Is.EqualTo("")); Assert.That(output.LeftLines[0].Change, Is.EqualTo(ChangeType.None)); Assert.That(output.LeftLines[1].Change, Is.EqualTo(ChangeType.Template)); Assert.That(output.RightLines[0].Change, Is.EqualTo(ChangeType.None)); Assert.That(output.RightLines[1].Change, Is.EqualTo(ChangeType.Template)); Assert.That(output.RightLines[1].IsVirtual, Is.True); }
public void TestGetConflictBefore_And_After() { TextFileInformation tfi = new TextFileInformation(); tfi.NewGenFile = new TextFile("line 0\r\nline 10\r\nline 2\r\nline32\r\nline 4\r\nline54\r\nline6"); tfi.UserFile = new TextFile("line 0\r\nline 12\r\nline 2\r\nline35\r\nline 4\r\nline56\r\nline6"); tfi.PrevGenFile = new TextFile("line 0\r\nline 1\r\nline 2\r\nline3\r\nline 4\r\nline5\r\nline6"); tfi.IntelliMerge = IntelliMergeType.PlainText; tfi.RelativeFilePath = "text.txt"; ThreeWayVisualDiff diffUtility = new ThreeWayVisualDiff(tfi); VisualDiffOutput output = diffUtility.ProcessMergeOutput(); Assert.IsNotNull(output); Assert.That(output.RightLines, Has.Count(10)); Assert.That(output.LeftLines, Has.Count(10)); VisualDiffOutput.ConflictRange conflict; Assert.That(output.IsLineInConflict(1), Is.True); Assert.That(output.IsLineInConflict(1, out conflict), Is.True); Assert.That(conflict, Is.Not.Null); Assert.That(conflict.StartLineIndex, Is.EqualTo(1)); Assert.That(conflict.EndLineIndex, Is.EqualTo(3)); Assert.That(output.GetConflictAfter(1).StartLineIndex, Is.EqualTo(4)); Assert.That(output.GetConflictBefore(1).StartLineIndex, Is.EqualTo(7)); Assert.That(output.GetConflictAfter(4).StartLineIndex, Is.EqualTo(7)); Assert.That(output.GetConflictBefore(4).StartLineIndex, Is.EqualTo(1)); }
private void AddUndoButtons() { ClearUndoButtons(); VisualDiffOutput diffOutput = mergeEditor.CurrentDiffInfo; if (editorOriginal.Visible == false || diffOutput == null) { return; } if (diffOutput.LeftLines.Count == 0) { return; } int firstDisplayLine = editorResolved.SelectedView.FirstVisibleDisplayLineIndex; int lineHeight = editorResolved.SelectedView.DisplayLineHeight; for (int i = firstDisplayLine; i < firstDisplayLine + editorResolved.SelectedView.VisibleDisplayLineCount && i < editorResolved.Document.Lines.Count; i++) { DocumentLine line = editorResolved.SelectedView.DisplayLines[i].DocumentLine; if ((diffOutput.RightLines[line.Index].Change & ChangeType.UserAndTemplate) == 0) { continue; } if (diffOutput.IsLineInConflict(line.Index)) { continue; } // Someone Deleted a line CreateButton(firstDisplayLine, i, lineHeight, mergeEditor.ResolvedButtonPanel, "Undo", "Undo your change", UndoButton_Click, UndoButtons); i = GetLastUndoLine(i, diffOutput.RightLines); } }
public void Files_Are_Exact_Copy() { TwoWayVisualDiff diffUtility = GetDiffUtility("line 1", "line 1"); VisualDiffOutput output = diffUtility.ProcessMergeOutput(); Assert.That(output, Is.Not.Null); Assert.That(output.LineCount, Is.EqualTo(1)); Assert.That(output.LeftLines[0].Text, Is.EqualTo("line 1")); Assert.That(output.RightLines[0].Text, Is.EqualTo("line 1")); }
private VisualDiffOutput CreateVisualDiffOutput() { VisualDiffOutput vdo = new VisualDiffOutput(); vdo.AddLine("line 0", Algorithm.Diff.ChangeType.None); vdo.AddLine("line 1", Algorithm.Diff.ChangeType.User, true); vdo.AddLine("line 2", Algorithm.Diff.ChangeType.Template, true); vdo.AddLine("line 3", Algorithm.Diff.ChangeType.None); vdo.ConflictRanges.Add(new VisualDiffOutput.ConflictRange(1, 3)); return(vdo); }
public void Line_Is_In_Conflict() { VisualDiffOutput vdo = new VisualDiffOutput(); vdo.AddLine("line 1", Algorithm.Diff.ChangeType.User, true); vdo.AddLine("line 2", Algorithm.Diff.ChangeType.Template, true); vdo.AddLine("line 3", Algorithm.Diff.ChangeType.None); vdo.ConflictRanges.Add(new VisualDiffOutput.ConflictRange(0, 2)); Assert.That(vdo.IsLineInConflict(0), "First line is in conflict."); Assert.That(vdo.IsLineInConflict(1), "Second line is in conflict."); Assert.That(vdo.IsLineInConflict(2), Is.False, "Third line is not a conflict."); }
private void UndoButton_Click(object sender, EventArgs e) { Button button = (Button)sender; int firstLine = (int)button.Tag; mergeEditor.ModifyingEditorText = true; // Find the last line VisualDiffOutput diffOutput = mergeEditor.CurrentDiffInfo; int lastLine = GetLastUndoLine(firstLine, diffOutput.RightLines); if (diffOutput.RightLines[firstLine].IsVirtual) // The user deleted the lines { // Copy the lines from prevgen. for (int i = lastLine; i >= firstLine; i--) { diffOutput.RightLines[i].Text = diffOutput.LeftLines[i].Text; diffOutput.RightLines[i].IsVirtual = diffOutput.LeftLines[i].IsVirtual = false; diffOutput.RightLines[i].Change = diffOutput.LeftLines[i].Change = ChangeType.None; editorResolved.Document.Lines[i].BackColor = Color.Empty; editorOriginal.Document.Lines[i].BackColor = Color.Empty; editorResolved.Document.Lines[i].Text = diffOutput.RightLines[i].Text; editorOriginal.Document.Lines[i].Text = diffOutput.LeftLines[i].Text; } } else { // Delete the lines for (int i = lastLine; i >= firstLine; i--) { editorResolved.Document.Lines[i].BackColor = Color.Empty; editorOriginal.Document.Lines[i].BackColor = Color.Empty; diffOutput.RemoveLine(i); editorResolved.Document.Lines.RemoveAt(i); editorOriginal.Document.Lines.RemoveAt(i); } } mergeEditor.ModifyingEditorText = false; AddButtons(); mergeEditor.SetLineNumbers(); mergeEditor.HasUnsavedChanges = true; }
public void Change_In_Middle() { TwoWayVisualDiff diffUtility = GetDiffUtility("line 1\nline 22\nline 3", "line 1\nline 2\nline 3"); VisualDiffOutput output = diffUtility.ProcessMergeOutput(); Assert.That(output.LineCount, Is.EqualTo(4)); CheckLines(output.LeftLines, new[] { false, false, false, false }); CheckLines(output.RightLines, new[] { false, true, true, false }); CheckLines(output.LeftLines, new[] { "line 1", "line 2", "line 22", "line 3" }); CheckLines(output.RightLines, new[] { "line 1", "", "", "line 3" }); CheckLines(output.LeftLines, new[] { ChangeType.None, ChangeType.User, ChangeType.Template, ChangeType.None }); CheckLines(output.RightLines, new[] { ChangeType.None, ChangeType.None, ChangeType.None, ChangeType.None }); }
public void User_Added_At_End() { TwoWayVisualDiff diffUtility = GetDiffUtility("line 1", "line 1\nline 2"); VisualDiffOutput output = diffUtility.ProcessMergeOutput(); Assert.That(output.LineCount, Is.EqualTo(2)); CheckLines(output.LeftLines, new[] { false, true }); CheckLines(output.RightLines, new[] { false, false }); CheckLines(output.LeftLines, new[] { "line 1", "" }); CheckLines(output.RightLines, new[] { "line 1", "line 2" }); CheckLines(output.LeftLines, new[] { ChangeType.None, ChangeType.None }); CheckLines(output.RightLines, new[] { ChangeType.None, ChangeType.User }); }
public void Template_Added_At_Start() { TwoWayVisualDiff diffUtility = GetDiffUtility("line 0\nline 1", "line 1"); VisualDiffOutput output = diffUtility.ProcessMergeOutput(); Assert.That(output.LineCount, Is.EqualTo(2)); CheckLines(output.LeftLines, new[] { true, false }); CheckLines(output.RightLines, new[] { false, false }); CheckLines(output.LeftLines, new[] { "", "line 1" }); CheckLines(output.RightLines, new[] { "line 0", "line 1" }); CheckLines(output.LeftLines, new[] { ChangeType.None, ChangeType.None }); CheckLines(output.RightLines, new[] { ChangeType.Template, ChangeType.None }); }
public void Conflict_Range_Doesnt_Move() { VisualDiffOutput vdo = CreateVisualDiffOutput(); Assert.That(vdo.IsLineInConflict(0), Is.False, "First line is not in conflict."); Assert.That(vdo.IsLineInConflict(1), "Second line is in conflict."); Assert.That(vdo.IsLineInConflict(2), "Third line is in conflict."); Assert.That(vdo.IsLineInConflict(3), Is.False, "Fourth line is not in conflict."); vdo.RemoveLine(3); Assert.That(vdo.LineCount, Is.EqualTo(3)); Assert.That(vdo.IsLineInConflict(0), Is.False, "First line is not in conflict."); Assert.That(vdo.IsLineInConflict(1), "Second line is in conflict."); Assert.That(vdo.IsLineInConflict(2), "Third line is in conflict."); }
public void TestConflictOperations_NoConflicts() { TextFileInformation tfi = new TextFileInformation(); tfi.NewGenFile = new TextFile("line 0\r\nline 1\r\nline 2"); tfi.IntelliMerge = IntelliMergeType.PlainText; tfi.RelativeFilePath = "text.txt"; ThreeWayVisualDiff diffUtility = new ThreeWayVisualDiff(tfi); VisualDiffOutput output = diffUtility.ProcessMergeOutput(); Assert.IsNotNull(output); Assert.That(output.IsLineInConflict(0), Is.False); Assert.That(output.GetConflictBefore(0), Is.Null); Assert.That(output.GetConflictAfter(0), Is.Null); }
public void TestToString() { TextFileInformation tfi = new TextFileInformation(); tfi.NewGenFile = new TextFile("line 0\r\nline 1\r\nline 2"); tfi.IntelliMerge = IntelliMergeType.PlainText; tfi.RelativeFilePath = "text.txt"; ThreeWayVisualDiff diffUtility = new ThreeWayVisualDiff(tfi); VisualDiffOutput output = diffUtility.ProcessMergeOutput(); Assert.IsNotNull(output); Assert.That(output.ToString().Contains("Left Lines")); Assert.That(output.ToString().Contains("Right Lines")); Assert.That(output.ToString().IndexOf("line 0"), Is.Not.EqualTo(output.ToString().LastIndexOf("line 0"))); }
/// <summary> /// Forces the control to update the contents of its editors, and display the diff results. /// </summary> internal void Fill() { BusyPopulatingEditors = true; if (fileInformation == null) { editorOriginal.Text = ""; editorResolved.Text = ""; BusyPopulatingEditors = false; return; } if (string.IsNullOrEmpty(fileInformation.CurrentDiffResult.DiffWarningDescription) == false) { WarningText = (string.IsNullOrEmpty(WarningText) ? "" : WarningText + Environment.NewLine) + fileInformation.CurrentDiffResult.DiffWarningDescription; } else { panelWarning.Visible = false; } editorOriginal.SuspendPainting(); editorResolved.SuspendPainting(); currentDiffInfo = displayAlgorithm.GetDiffOutput(); editorOriginal.Document.Text = ""; editorResolved.Document.Text = ""; if (CurrentDiffInfo.DiffType == TypeOfDiff.Conflict) { EnableEditing(true); } FillEditors(); editorOriginal.SelectedView.ScrollToDocumentStart(); editorResolved.SelectedView.ScrollToDocumentStart(); displayAlgorithm.AddButtons(); HasUnsavedChanges = false; Refresh(); editorOriginal.ResumePainting(); editorResolved.ResumePainting(); BusyPopulatingEditors = false; }
public void TestConflict_At_Start_Add_At_End() { TextFileInformation tfi = new TextFileInformation(); tfi.PrevGenFile = new TextFile("line1\nline3"); tfi.UserFile = new TextFile("line00\nline1\nline2\nline3"); tfi.NewGenFile = new TextFile("line0\nline1\nline3\nline4"); tfi.IntelliMerge = IntelliMergeType.PlainText; tfi.RelativeFilePath = "text.txt"; ThreeWayVisualDiff diffUtility = new ThreeWayVisualDiff(tfi); VisualDiffOutput output = diffUtility.ProcessMergeOutput(); Assert.IsNotNull(output); Assert.That(output.RightLines, Is.Not.Empty); Assert.That(output.LeftLines, Is.Not.Empty); Assert.That(output.LeftLines, Has.Count(6)); Assert.That(output.RightLines, Has.Count(6)); Assert.That(output.LeftLines[0].Text, Is.EqualTo("line00"), "Line 1 on left"); Assert.That(output.LeftLines[1].Text, Is.EqualTo("line0"), "Line 2 on left"); Assert.That(output.LeftLines[2].Text, Is.EqualTo("line1"), "Line 3 on left"); Assert.That(output.LeftLines[3].Text, Is.EqualTo(""), "Line 4 on left"); Assert.That(output.LeftLines[4].Text, Is.EqualTo("line3"), "Line 5 on left"); Assert.That(output.LeftLines[5].Text, Is.EqualTo(""), "Line 5 on left"); Assert.That(output.RightLines[0].Text, Is.EqualTo(""), "Line 1 on right"); Assert.That(output.RightLines[1].Text, Is.EqualTo(""), "Line 2 on right"); Assert.That(output.RightLines[2].Text, Is.EqualTo("line1"), "Line 3 on right"); Assert.That(output.RightLines[3].Text, Is.EqualTo("line2"), "Line 4 on right"); Assert.That(output.RightLines[4].Text, Is.EqualTo("line3"), "Line 5 on right"); Assert.That(output.RightLines[5].Text, Is.EqualTo("line4"), "Line 6 on right"); Assert.That(output.LeftLines[0].Change, Is.EqualTo(ChangeType.User)); Assert.That(output.LeftLines[1].Change, Is.EqualTo(ChangeType.Template)); Assert.That(output.LeftLines[2].Change, Is.EqualTo(ChangeType.None)); Assert.That(output.LeftLines[3].IsVirtual, Is.True); Assert.That(output.LeftLines[4].Change, Is.EqualTo(ChangeType.None)); Assert.That(output.LeftLines[5].IsVirtual, Is.True); Assert.That(output.RightLines[0].IsVirtual, Is.True); Assert.That(output.RightLines[1].IsVirtual, Is.True); Assert.That(output.RightLines[2].Change, Is.EqualTo(ChangeType.None)); Assert.That(output.RightLines[3].Change, Is.EqualTo(ChangeType.User)); Assert.That(output.RightLines[4].Change, Is.EqualTo(ChangeType.None)); Assert.That(output.RightLines[5].Change, Is.EqualTo(ChangeType.Template)); }
public void TestExactCopy() { TextFileInformation tfi = new TextFileInformation(); tfi.NewGenFile = new TextFile("aklsdjflkjasdf"); tfi.IntelliMerge = IntelliMergeType.PlainText; tfi.RelativeFilePath = "text.txt"; ThreeWayVisualDiff diffUtility = new ThreeWayVisualDiff(tfi); VisualDiffOutput output = diffUtility.ProcessMergeOutput(); Assert.IsNotNull(output); Assert.That(output.DiffType, Is.EqualTo(TypeOfDiff.ExactCopy)); Assert.That(output.RightLines, Has.Count(1)); Assert.That(output.LeftLines, Has.Count(1)); Assert.That(output.LeftLines[0].Text, Is.EqualTo(tfi.NewGenFile.GetContents())); Assert.That(output.RightLines[0].Text, Is.EqualTo(tfi.NewGenFile.GetContents())); }
public void Conflict_Range_Shrinks_Correctly() { VisualDiffOutput vdo = CreateVisualDiffOutput(); Assert.That(vdo.IsLineInConflict(0), Is.False, "First line is not in conflict."); Assert.That(vdo.IsLineInConflict(1), "Second line is in conflict."); Assert.That(vdo.IsLineInConflict(2), "Third line is in conflict."); Assert.That(vdo.IsLineInConflict(3), Is.False, "Fourth line is not in conflict."); vdo.RemoveLine(2); Assert.That(vdo.LineCount, Is.EqualTo(3)); Assert.That(vdo.IsLineInConflict(0), Is.False, "First line is not in conflict."); Assert.That(vdo.IsLineInConflict(1), "Second line is in conflict."); Assert.That(vdo.IsLineInConflict(2), Is.False, "Third line is not in conflict."); Assert.That(vdo.ConflictRanges[0].StartLineIndex, Is.EqualTo(1)); Assert.That(vdo.ConflictRanges[0].EndLineIndex, Is.EqualTo(2)); }
public void Files_Are_Exact_Copy_PrevGen_Missing() { TextFileInformation tfi = new TextFileInformation(); tfi.PrevGenFile = TextFile.Blank; tfi.UserFile = tfi.NewGenFile = new TextFile("line 1"); tfi.IntelliMerge = IntelliMergeType.PlainText; tfi.RelativeFilePath = "text.txt"; TwoWayVisualDiff diffUtility = new TwoWayVisualDiff(tfi); VisualDiffOutput output = diffUtility.ProcessMergeOutput(); Assert.That(output, Is.Not.Null); Assert.That(output.LineCount, Is.EqualTo(1)); Assert.That(output.LeftLines[0].Text, Is.EqualTo("line 1")); Assert.That(output.RightLines[0].Text, Is.EqualTo("line 1")); }
public void UserAndTemplate_Two_Changes_In_Middle() { TextFileInformation tfi = new TextFileInformation(); tfi.PrevGenFile = new TextFile("line0\nline1\nline2\nline3"); tfi.UserFile = new TextFile("line0\nline11\nline12\nline2\nline3"); tfi.NewGenFile = new TextFile("line0\nline1\nline21\nline3"); tfi.IntelliMerge = IntelliMergeType.PlainText; tfi.RelativeFilePath = "text.txt"; ThreeWayVisualDiff diffUtility = new ThreeWayVisualDiff(tfi); VisualDiffOutput output = diffUtility.ProcessMergeOutput(); Assert.That(output.DiffType, Is.EqualTo(Slyce.IntelliMerge.TypeOfDiff.UserAndTemplateChange)); Assert.IsNotNull(output); Assert.That(output.RightLines, Is.Not.Empty); Assert.That(output.LeftLines, Is.Not.Empty); Assert.That(output.LeftLines, Has.Count(5)); Assert.That(output.RightLines, Has.Count(5)); Assert.That(output.LeftLines[0].Text, Is.EqualTo("line0")); Assert.That(output.LeftLines[1].Text, Is.EqualTo("line1")); Assert.That(output.LeftLines[2].Text, Is.EqualTo("")); Assert.That(output.LeftLines[3].Text, Is.EqualTo("line2")); Assert.That(output.LeftLines[4].Text, Is.EqualTo("line3")); Assert.That(output.RightLines[0].Text, Is.EqualTo("line0")); Assert.That(output.RightLines[1].Text, Is.EqualTo("line11")); Assert.That(output.RightLines[2].Text, Is.EqualTo("line12")); Assert.That(output.RightLines[3].Text, Is.EqualTo("line21")); Assert.That(output.RightLines[4].Text, Is.EqualTo("line3")); Assert.That(output.LeftLines[0].Change, Is.EqualTo(ChangeType.None)); Assert.That(output.LeftLines[1].Change, Is.EqualTo(ChangeType.User)); Assert.That(output.LeftLines[2].Change, Is.EqualTo(ChangeType.User)); Assert.That(output.LeftLines[2].IsVirtual, Is.EqualTo(true)); Assert.That(output.LeftLines[3].Change, Is.EqualTo(ChangeType.Template)); Assert.That(output.LeftLines[4].Change, Is.EqualTo(ChangeType.None)); Assert.That(output.RightLines[0].Change, Is.EqualTo(ChangeType.None)); Assert.That(output.RightLines[1].Change, Is.EqualTo(ChangeType.User)); Assert.That(output.RightLines[2].Change, Is.EqualTo(ChangeType.User)); Assert.That(output.RightLines[3].Change, Is.EqualTo(ChangeType.Template)); Assert.That(output.RightLines[4].Change, Is.EqualTo(ChangeType.None)); }
public void Conflict_Range_Moves_Correctly() { VisualDiffOutput vdo = new VisualDiffOutput(); vdo.AddLine("line 0", Algorithm.Diff.ChangeType.None); vdo.AddLine("line 1", Algorithm.Diff.ChangeType.User, true); vdo.AddLine("line 2", Algorithm.Diff.ChangeType.Template, true); vdo.ConflictRanges.Add(new VisualDiffOutput.ConflictRange(1, 3)); Assert.That(vdo.IsLineInConflict(0), Is.False, "First line is not in conflict."); Assert.That(vdo.IsLineInConflict(1), "Second line is in conflict."); Assert.That(vdo.IsLineInConflict(2), "Third line is in conflict."); vdo.RemoveLine(0); Assert.That(vdo.LineCount, Is.EqualTo(2)); Assert.That(vdo.IsLineInConflict(0), "First line is in conflict."); Assert.That(vdo.IsLineInConflict(1), "Second line is in conflict."); }
public void TestDeleteLine() { TextFileInformation tfi = new TextFileInformation(); tfi.NewGenFile = new TextFile("line 0\r\nline 1\r\nline 2"); tfi.IntelliMerge = IntelliMergeType.PlainText; tfi.RelativeFilePath = "text.txt"; ThreeWayVisualDiff diffUtility = new ThreeWayVisualDiff(tfi); VisualDiffOutput output = diffUtility.ProcessMergeOutput(); Assert.IsNotNull(output); Assert.That(output.RightLines, Has.Count(3)); Assert.That(output.LeftLines, Has.Count(3)); output.RemoveLine(0); Assert.That(output.RightLines, Has.Count(2)); Assert.That(output.LeftLines, Has.Count(2)); Assert.That(output.RightLines[0].Text, Is.EqualTo("line 1")); Assert.That(output.LeftLines[0].Text, Is.EqualTo("line 1")); }
private void AddApplyButtons() { ClearApplyButtons(); VisualDiffOutput diffOutput = mergeEditor.CurrentDiffInfo; if (editorOriginal.Visible == false || diffOutput == null) { return; } if (diffOutput.LeftLines.Count == 0) { return; } int firstDisplayLine = editorOriginal.SelectedView.FirstVisibleDisplayLineIndex; int lineHeight = editorOriginal.SelectedView.DisplayLineHeight; for (int i = firstDisplayLine; i < firstDisplayLine + editorOriginal.SelectedView.VisibleDisplayLineCount && i < editorOriginal.Document.Lines.Count; i++) { DocumentLine line = editorOriginal.SelectedView.DisplayLines[i].DocumentLine; VisualDiffOutput.ConflictRange conflict; if (diffOutput.IsLineInConflict(line.Index, out conflict) == false) { continue; } // Conflict CreateButton(firstDisplayLine, i, lineHeight, mergeEditor.OriginalButtonPanel, "Apply", "Apply the user change", ApplyButton_Click, ApplyButtons); // Figure out where the template change starts int j = i; for (; j < conflict.EndLineIndex && diffOutput.LeftLines[j].Change == ChangeType.User; j++) { } CreateButton(firstDisplayLine, j, lineHeight, mergeEditor.OriginalButtonPanel, "Apply", "Apply the template change", ApplyButton_Click, ApplyButtons); i = conflict.EndLineIndex; } }
private void ApplyButton_Click(object sender, EventArgs e) { Button button = (Button)sender; int firstLine = (int)button.Tag; mergeEditor.ModifyingEditorText = true; // Find the last line int lastLine = firstLine; VisualDiffOutput diffOutput = mergeEditor.CurrentDiffInfo; ChangeType currentChangeType = diffOutput.LeftLines[firstLine].Change; if (currentChangeType == diffOutput.RightLines[lastLine].Change && diffOutput.RightLines[firstLine].IsVirtual) { while (lastLine < diffOutput.RightLines.Count - 1 && currentChangeType == diffOutput.RightLines[lastLine + 1].Change && diffOutput.RightLines[lastLine + 1].IsVirtual) { lastLine++; } } else { while (lastLine < diffOutput.LeftLines.Count - 1 && diffOutput.LeftLines[lastLine + 1].Change == currentChangeType && diffOutput.LeftLines[lastLine + 1].IsVirtual == false) { lastLine++; } } // Copy all the lines over from left to right. for (int i = firstLine; i <= lastLine; i++) { editorResolved.Document.Lines[i].Text = editorOriginal.Document.Lines[i].Text; diffOutput.RightLines[i].Text = diffOutput.LeftLines[i].Text; diffOutput.RightLines[i].Change = ChangeType.None; diffOutput.LeftLines[i].Change = ChangeType.None; diffOutput.RightLines[i].IsVirtual = false; diffOutput.LeftLines[i].IsVirtual = false; editorResolved.Document.Lines[i].BackColor = Color.Empty; editorOriginal.Document.Lines[i].BackColor = Color.Empty; } VisualDiffOutput.ConflictRange conflictRange; if (diffOutput.IsLineInConflict(firstLine, out conflictRange)) { for (int i = conflictRange.EndLineIndex - 1; i >= conflictRange.StartLineIndex; i--) { diffOutput.LeftLines[i].IsVirtual = false; diffOutput.RightLines[i].IsVirtual = false; // The copied lines in the conflict region are now marked with ChangeType.None if (diffOutput.LeftLines[i].Change == ChangeType.None) { continue; } editorResolved.Document.Lines[i].BackColor = Color.Empty; editorOriginal.Document.Lines[i].BackColor = Color.Empty; editorOriginal.Document.Lines.RemoveAt(i); editorResolved.Document.Lines.RemoveAt(i); diffOutput.RemoveLine(i); } } diffOutput.ConflictRanges.Remove(conflictRange); mergeEditor.ModifyingEditorText = false; AddButtons(); mergeEditor.SetLineNumbers(); mergeEditor.HasUnsavedChanges = true; }