private IList <TextMarker> GetTextMarkersMatchingWord(string word) { if (word.IsNullOrWhiteSpace()) { return(Array.Empty <TextMarker>()); } var selectionMarkers = new List <TextMarker>(); string textContent = TextEditor.Document.TextContent; int indexMatch = -1; do { indexMatch = textContent.IndexOf(word, indexMatch + 1, StringComparison.OrdinalIgnoreCase); if (indexMatch >= 0) { Color highlightColor = AppSettings.HighlightAllOccurencesColor; var textMarker = new TextMarker(indexMatch, word.Length, TextMarkerType.SolidBlock, highlightColor, ColorHelper.GetForeColorForBackColor(highlightColor)); selectionMarkers.Add(textMarker); } }while (indexMatch >= 0 && indexMatch < textContent.Length - 1); return(selectionMarkers); }
private void MarkDifference(IDocument document, LineSegment lineRemoved, LineSegment lineAdded, int beginOffset) { var lineRemovedEndOffset = lineRemoved.Length; var lineAddedEndOffset = lineAdded.Length; var endOffsetMin = Math.Min(lineRemovedEndOffset, lineAddedEndOffset); var reverseOffset = 0; while (beginOffset < endOffsetMin) { if (!document.GetCharAt(lineAdded.Offset + beginOffset).Equals( document.GetCharAt(lineRemoved.Offset + beginOffset))) { break; } beginOffset++; } while (lineAddedEndOffset > beginOffset && lineRemovedEndOffset > beginOffset) { reverseOffset = lineAdded.Length - lineAddedEndOffset; if (!document.GetCharAt(lineAdded.Offset + lineAdded.Length - 1 - reverseOffset). Equals(document.GetCharAt(lineRemoved.Offset + lineRemoved.Length - 1 - reverseOffset))) { break; } lineRemovedEndOffset--; lineAddedEndOffset--; } Color color; var markerStrategy = document.MarkerStrategy; if (lineAdded.Length - beginOffset - reverseOffset > 0) { color = Settings.DiffAddedExtraColor; markerStrategy.AddMarker(new TextMarker(lineAdded.Offset + beginOffset, lineAdded.Length - beginOffset - reverseOffset, TextMarkerType.SolidBlock, color, ColorHelper.GetForeColorForBackColor(color))); } if (lineRemoved.Length - beginOffset - reverseOffset > 0) { color = Settings.DiffRemovedExtraColor; markerStrategy.AddMarker(new TextMarker(lineRemoved.Offset + beginOffset, lineRemoved.Length - beginOffset - reverseOffset, TextMarkerType.SolidBlock, color, ColorHelper.GetForeColorForBackColor(color))); } }
private void ProcessLineSegment(ref int line, LineSegment lineSegment, char signChar, Color color) { var document = TextEditor.Document; if (document.GetCharAt(lineSegment.Offset) == signChar) { var endLine = document.GetLineSegment(line); for (; line < document.TotalNumberOfLines && document.GetCharAt(endLine.Offset) == signChar; line++) { endLine = document.GetLineSegment(line); } line--; line--; endLine = document.GetLineSegment(line); document.MarkerStrategy.AddMarker(new TextMarker(lineSegment.Offset, (endLine.Offset + endLine.TotalLength) - lineSegment.Offset, TextMarkerType.SolidBlock, color, ColorHelper.GetForeColorForBackColor(color))); } }
private void AddExtraPatchHighlighting() { var document = TextEditor.Document; var markerStrategy = document.MarkerStrategy; for (var line = 0; line + 3 < document.TotalNumberOfLines; line++) { var lineSegment1 = document.GetLineSegment(line); var lineSegment2 = document.GetLineSegment(line + 1); var lineSegment3 = document.GetLineSegment(line + 2); var lineSegment4 = document.GetLineSegment(line + 3); if (document.GetCharAt(lineSegment1.Offset) != ' ' || document.GetCharAt(lineSegment2.Offset) != '-' || document.GetCharAt(lineSegment3.Offset) != '+' || (lineSegment4.Length > 0 && document.GetCharAt(lineSegment4.Offset) != ' ')) //fix for issue 173 { continue; } var beginOffset = 0; var endOffset = lineSegment3.Length; var reverseOffset = 0; for (; beginOffset < endOffset; beginOffset++) { if (!document.GetCharAt(lineSegment3.Offset + beginOffset).Equals('+') && !document.GetCharAt(lineSegment2.Offset + beginOffset).Equals('-') && !document.GetCharAt(lineSegment3.Offset + beginOffset).Equals( document.GetCharAt(lineSegment2.Offset + beginOffset))) { break; } } for (; endOffset > beginOffset; endOffset--) { reverseOffset = lineSegment3.Length - endOffset; if (!document.GetCharAt(lineSegment3.Offset + lineSegment3.Length - 1 - reverseOffset) .Equals('+') && !document.GetCharAt(lineSegment2.Offset + lineSegment2.Length - 1 - reverseOffset) .Equals('-') && !document.GetCharAt(lineSegment3.Offset + lineSegment3.Length - 1 - reverseOffset). Equals(document.GetCharAt(lineSegment2.Offset + lineSegment2.Length - 1 - reverseOffset))) { break; } } Color color; if (lineSegment3.Length - beginOffset - reverseOffset > 0) { color = Settings.DiffAddedExtraColor; markerStrategy.AddMarker(new TextMarker(lineSegment3.Offset + beginOffset, lineSegment3.Length - beginOffset - reverseOffset, TextMarkerType.SolidBlock, color, ColorHelper.GetForeColorForBackColor(color))); } if (lineSegment2.Length - beginOffset - reverseOffset > 0) { color = Settings.DiffRemovedExtraColor; markerStrategy.AddMarker(new TextMarker(lineSegment2.Offset + beginOffset, lineSegment2.Length - beginOffset - reverseOffset, TextMarkerType.SolidBlock, color, ColorHelper.GetForeColorForBackColor(color))); } } }
public void AddPatchHighlighting() { var document = TextEditor.Document; var markerStrategy = document.MarkerStrategy; markerStrategy.RemoveAll(m => true); bool forceAbort = false; AddExtraPatchHighlighting(); for (var line = 0; line < document.TotalNumberOfLines && !forceAbort; line++) { var lineSegment = document.GetLineSegment(line); if (lineSegment.TotalLength == 0) { continue; } if (line == document.TotalNumberOfLines - 1) { forceAbort = true; } if (document.GetCharAt(lineSegment.Offset) == '+') { var color = Settings.DiffAddedColor; var endLine = document.GetLineSegment(line); for (; line < document.TotalNumberOfLines && document.GetCharAt(endLine.Offset) == '+'; line++) { endLine = document.GetLineSegment(line); } line--; line--; endLine = document.GetLineSegment(line); markerStrategy.AddMarker(new TextMarker(lineSegment.Offset, (endLine.Offset + endLine.TotalLength) - lineSegment.Offset, TextMarkerType.SolidBlock, color, ColorHelper.GetForeColorForBackColor(color))); } if (document.GetCharAt(lineSegment.Offset) == '-') { var color = Settings.DiffRemovedColor; var endLine = document.GetLineSegment(line); for (; line < document.TotalNumberOfLines && document.GetCharAt(endLine.Offset) == '-'; line++) { endLine = document.GetLineSegment(line); } line--; line--; endLine = document.GetLineSegment(line); markerStrategy.AddMarker(new TextMarker(lineSegment.Offset, (endLine.Offset + endLine.TotalLength) - lineSegment.Offset, TextMarkerType.SolidBlock, color, ColorHelper.GetForeColorForBackColor(color))); } if (document.GetCharAt(lineSegment.Offset) == '@') { var color = Settings.DiffSectionColor; var endLine = document.GetLineSegment(line); for (; line < document.TotalNumberOfLines && document.GetCharAt(endLine.Offset) == '@'; line++) { endLine = document.GetLineSegment(line); } line--; line--; endLine = document.GetLineSegment(line); markerStrategy.AddMarker(new TextMarker(lineSegment.Offset, (endLine.Offset + endLine.TotalLength) - lineSegment.Offset, TextMarkerType.SolidBlock, color, ColorHelper.GetForeColorForBackColor(color))); } } }