private static DiffLine CreateDiffLine(string line, int number) { var diffLine = new DiffLine { Line = line, Number = number }; switch (line[0]) { case '+': diffLine.CssCodeClass = ADDITION_CSS_CODE_CLASS; diffLine.CssNumClass = ADDITION_CSS_NUM_CLASS; break; case '-': diffLine.CssCodeClass = DELETION_CSS_CODE_CLASS; diffLine.CssNumClass = DELETION_CSS_NUM_CLASS; break; default: diffLine.CssCodeClass = NORMAL_CSS_CODE_CLASS; diffLine.CssNumClass = NORMAL_CSS_NUM_CLASS; break; } return(diffLine); }
public DiffLine[] GetSelectedLines() { if (_selStart == -1) { return(new DiffLine[0]); } int offset = 0; int i = 0; int num = _selStart; while (_diffFile[i].LineCount <= num) { int lc = _diffFile[i].LineCount; offset += lc; num -= lc; ++i; } int count = _selEnd - _selStart + 1; var res = new DiffLine[count]; int id = 0; while (id != res.Length) { res[id++] = _diffFile[i][num++]; if (num >= _diffFile[i].LineCount) { ++i; num = 0; } } return(res); }
internal void SetLineNumbers() { int lineNumber = 1; for (int i = 0; i < currentDiffInfo.RightLines.Count; i++) { DiffLine line = currentDiffInfo.RightLines[i]; if (line.IsVirtual == false) { editorResolved.Document.Lines[i].CustomLineNumber = lineNumber.ToString(); lineNumber++; } else { editorResolved.Document.Lines[i].CustomLineNumber = string.Empty; } } lineNumber = 1; for (int i = 0; i < currentDiffInfo.LeftLines.Count; i++) { DiffLine line = currentDiffInfo.LeftLines[i]; if (line.IsVirtual == false) { editorOriginal.Document.Lines[i].CustomLineNumber = lineNumber.ToString(); lineNumber++; } else { editorOriginal.Document.Lines[i].CustomLineNumber = string.Empty; } } }
public void FillEditors() { StringBuilder left = new StringBuilder(); StringBuilder right = new StringBuilder(); for (int i = 0; i < CurrentDiffInfo.LeftLines.Count; i++) { DiffLine leftline = CurrentDiffInfo.LeftLines[i]; DiffLine rightline = CurrentDiffInfo.RightLines[i]; left.AppendFormat("{0}{1}", i != 0 ? Environment.NewLine : "", leftline.Text); right.AppendFormat("{0}{1}", i != 0 ? Environment.NewLine : "", rightline.Text); } editorOriginal.SuspendPainting(); editorResolved.SuspendPainting(); modifyingEditorText = true; editorOriginal.Document.ReplaceText(DocumentModificationType.ReplaceAll, 0, editorOriginal.Document.Length, left.ToString()); editorResolved.Document.ReplaceText(DocumentModificationType.ReplaceAll, 0, editorResolved.Document.Length, right.ToString()); modifyingEditorText = false; editorOriginal.ResumePainting(); editorResolved.ResumePainting(); RecalculateVisualAspects(); }
public void NoLineMatchesFromNoLines() { var chunks = new DiffChunk[0]; var lines = new DiffLine[0]; var line = DiffUtilities.Match(chunks, lines); Assert.Null(line); }
private static DiffLine SetMarkdownCodeShell(this DiffLine line, string codeAlias) { if (codeAlias != null) { line.Line = $"```{codeAlias}\n{line.Line}\n```"; line.HasMarkdown = true; } return(line); }
public void AddRemoteLog(string remoteLog) { DebugLog("Adding remote log..."); var localClient = GeneralUtilities.localClient(); if (localClient == null) { DebugLog("No local client. Clearing logs and setting logs directly."); Clear(); AddPublic(remoteLog); ChatLog.SetLog(remoteLog); G.Sys.GameManager_.StartCoroutine(RemoveEventListenersCoroutine()); return; } DebugLog("Adding logs from the server:"); string[] remoteLogArray = System.Text.RegularExpressions.Regex.Split(remoteLog, $"\r\n|\n|\r"); var localNetworkPlayer = localClient.NetworkPlayer_; var personalBuffer = GetPersonalBuffer(localNetworkPlayer); DebugLog($"\nPublic log:\n{GetBufferString(publicChatBuffer)}"); DebugLog($"\nPersonal log:\n{GetBufferString(personalBuffer)}"); DebugLog($"\nRemote log:\n{remoteLog}"); List <DiffLine> publicDiff = DiffLine.GetDiffLines(publicChatBuffer); DiffLine.ExecuteDiff(publicDiff, remoteLogArray); string publicLog = DiffLine.DiffLinesToString(publicDiff); DebugLog($"\nPublic diff:\n{DiffLine.DiffLinesToStringInfo(publicDiff)}"); List <DiffLine> personalDiff = publicDiff; DiffLine.ExecuteDiff(personalDiff, personalBuffer, DiffLine.DiffOptions.AddFirst); string personalLog = DiffLine.DiffLinesToString(personalDiff); publicChatBuffer.Clear(); AddPublicNoPersonal(publicLog); personalBuffer.Clear(); AddPersonalNoAddLocal(localNetworkPlayer, personalLog); DebugLog($"\nFinal diff:\n{DiffLine.DiffLinesToStringInfo(personalDiff)}"); ChatLog.SetLog(personalLog); foreach (var chatInput in PrivateUtilities.getComponents <ChatInputV2>()) { PrivateUtilities.callPrivateMethod(chatInput, "OnEventSetServerChat", new SetServerChat.Data(personalLog)); } }
public void DiffSection_True_Line() { var lineDelete = new DiffLine { Type = DiffLineType.DiffLineDelete, Content = "- <groupId>com.ambientideas</groupId>", LeftLine = 4, RightLine = 0 }; var lineAdd = new DiffLine { Type = DiffLineType.DiffLineAdd, Content = "+ <groupId>com.github</groupId", LeftLine = 0, RightLine = 4 }; var section = new DiffSection { Lines = new List <DiffLine> { new DiffLine { Type = DiffLineType.DiffLineSection, Content = "@@ -1,7 +1,7 @@" }, new DiffLine { Type = DiffLineType.DiffLinePlain, Content = " <project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"", LeftLine = 1, RightLine = 1 }, new DiffLine { Type = DiffLineType.DiffLinePlain, Content = " xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\">", LeftLine = 2, RightLine = 2 }, new DiffLine { Type = DiffLineType.DiffLinePlain, Content = " <modelVersion>4.0.0</modelVersion>", LeftLine = 3, RightLine = 3 }, lineDelete, lineAdd, new DiffLine { Type = DiffLineType.DiffLinePlain, Content = " <artifactId>egitdemo</artifactId>", LeftLine = 5, RightLine = 5 }, new DiffLine { Type = DiffLineType.DiffLinePlain, Content = " <packaging>jar</packaging>", LeftLine = 6, RightLine = 6 }, new DiffLine { Type = DiffLineType.DiffLinePlain, Content = " <version>1.0-SNAPSHOT</version>", LeftLine = 7, RightLine = 7 } } }; var del = section.Line(lineDelete.Type, 4); Assert.Equal(lineDelete, del); var add = section.Line(lineAdd.Type, 4); Assert.Equal(lineAdd, add); }
private void PaintLine( int lineIndex, DiffLine line, int digits, Graphics graphics, Font font, bool isHovered, bool isSelected, int x, int y, int width) { int cols = line.Nums.Length; var rcColNumbers = new Rectangle(x, y, digits * CellSize.Width * cols + 2, CellSize.Height); Brush backgroundBrush; if (cols != 0) { using (backgroundBrush = isHovered ? GetLineNumberHoverBackground() : GetLineNumberBackground()) { graphics.FillRectangle(backgroundBrush, rcColNumbers); } using (var brush = GetLineNumberText()) { for (int i = 0; i < cols; ++i) { switch (line.States[i]) { case DiffLineState.Added: PaintLineColumnImage(graphics, i, digits, ImgPlus, x, y); break; case DiffLineState.Removed: PaintLineColumnImage(graphics, i, digits, ImgMinus, x, y); break; case DiffLineState.Header: PaintLineColumnText(graphics, font, brush, i, digits, x, y, "..."); break; default: PaintLineColumnText(graphics, font, brush, i, digits, x, y, line.Nums[i].ToString(CultureInfo.InvariantCulture)); break; } int lineX = x + i * digits * CellSize.Width + ((i == 0) ? 0 : 2); graphics.DrawLine(Pens.Gray, lineX, y, lineX, y + CellSize.Height); } } } { int lineX = x + cols * digits * CellSize.Width + (cols != 0?1:0); graphics.DrawLine(Pens.Gray, lineX, y, lineX, y + CellSize.Height); lineX = x + width - Margin * 2 - 1; graphics.DrawLine(Pens.Gray, lineX, y, lineX, y + CellSize.Height); } var rcLine = new Rectangle( x + rcColNumbers.Width, y, width - 2 * Margin - rcColNumbers.Width - 1, CellSize.Height); if (isHovered) { backgroundBrush = isSelected ? GetLineSelectedHoverBackground() : GetLineHoverBackground(); } else { backgroundBrush = isSelected ? GetLineSelectedBackground() : GetLineBackgroundBrush(line.State); } using (backgroundBrush) { graphics.FillRectangle(backgroundBrush, rcLine); using (var foregroundBrush = GetLineForegroundBrush(line.State)) { GitterApplication.TextRenderer.DrawText( graphics, line.Text, font, foregroundBrush, rcLine.X + CellSize.Width / 2, rcLine.Y, ContentFormat); } } }
protected override Size OnMeasure(FlowPanelMeasureEventArgs measureEventArgs) { if (_diffFile == null) { return(Size.Empty); } if (_size.IsEmpty) { int maxLength = 0; int lines = 0; DiffLine longestLine = null; int largestNumber = 0; int maxCols = 0; foreach (var hunk in _diffFile) { foreach (var line in hunk) { int l = line.GetCharacterPositions(TabSize); if (l > maxLength) { maxLength = l; longestLine = line; } ++lines; } if (hunk.ColumnCount != 0) { var num = hunk.MaxLineNum; if (num > largestNumber) { largestNumber = num; } if (hunk.ColumnCount > maxCols) { maxCols = hunk.ColumnCount; } } } int digits; if (maxCols != 0) { digits = GetDecimalDigits(largestNumber); } else { digits = 0; } var font = GitterApplication.FontManager.ViewerFont.Font; int w = CellSize.Width * maxCols * digits + 2 * Margin; if (longestLine != null) { int longestLineWidth; try { longestLineWidth = GitterApplication.TextRenderer.MeasureText( measureEventArgs.Graphics, longestLine.Text, font, int.MaxValue, ContentFormat).Width + CellSize.Width; } catch (Exception exc) { if (exc.IsCritical()) { throw; } longestLineWidth = (int)(maxLength * CellSize.Width); } w += longestLineWidth; } var h = HeaderHeight + lines * CellSize.Height + (_diffFile.LineCount != 0 ? 1 : 0); _size = new Size(w, h); } return(_size); }
private void PaintLine( int lineIndex, DiffLine line, int digits, Graphics graphics, Font font, bool isHovered, bool isSelected, int x, int y, int width) { int cols = line.Nums.Length; var rcColNumbers = new Rectangle(x, y, digits * CellSize.Width * cols + 2, CellSize.Height); Brush backgroundBrush; if(cols != 0) { using(backgroundBrush = isHovered ? GetLineNumberHoverBackground() : GetLineNumberBackground()) { graphics.FillRectangle(backgroundBrush, rcColNumbers); } using(var brush = GetLineNumberText()) { for(int i = 0; i < cols; ++i) { switch(line.States[i]) { case DiffLineState.Added: PaintLineColumnImage(graphics, i, digits, ImgPlus, x, y); break; case DiffLineState.Removed: PaintLineColumnImage(graphics, i, digits, ImgMinus, x, y); break; case DiffLineState.Header: PaintLineColumnText(graphics, font, brush, i, digits, x, y, "..."); break; default: PaintLineColumnText(graphics, font, brush, i, digits, x, y, line.Nums[i].ToString(CultureInfo.InvariantCulture)); break; } int lineX = x + i * digits * CellSize.Width + ((i == 0) ? 0 : 2); graphics.DrawLine(Pens.Gray, lineX, y, lineX, y + CellSize.Height); } } } { int lineX = x + cols * digits * CellSize.Width + (cols != 0?1:0); graphics.DrawLine(Pens.Gray, lineX, y, lineX, y + CellSize.Height); lineX = x + width - Margin * 2 - 1; graphics.DrawLine(Pens.Gray, lineX, y, lineX, y + CellSize.Height); } var rcLine = new Rectangle( x + rcColNumbers.Width, y, width - 2*Margin - rcColNumbers.Width- 1, CellSize.Height); if(isHovered) { backgroundBrush = isSelected ? GetLineSelectedHoverBackground() : GetLineHoverBackground(); } else { backgroundBrush = isSelected ? GetLineSelectedBackground() : GetLineBackgroundBrush(line.State); } using(backgroundBrush) { graphics.FillRectangle(backgroundBrush, rcLine); using(var foregroundBrush = GetLineForegroundBrush(line.State)) { GitterApplication.TextRenderer.DrawText( graphics, line.Text, font, foregroundBrush, rcLine.X + CellSize.Width / 2, rcLine.Y, ContentFormat); } } }
public DiffLine[] GetSelectedLines() { if(_selStart == -1) return new DiffLine[0]; int offset = 0; int i = 0; int num = _selStart; while(_diffFile[i].LineCount <= num) { int lc = _diffFile[i].LineCount; offset += lc; num -= lc; ++i; } int count = _selEnd - _selStart + 1; var res = new DiffLine[count]; int id = 0; while(id != res.Length) { res[id++] = _diffFile[i][num++]; if(num >= _diffFile[i].LineCount) { ++i; num = 0; } } return res; }