Skip to content
This repository has been archived by the owner on Oct 4, 2021. It is now read-only.

Commit

Permalink
Merge pull request #234 from IBBoard/master
Browse files Browse the repository at this point in the history
Fix highlighting in diffs
  • Loading branch information
mkrueger committed Nov 12, 2012
2 parents 4651766 + 8a6ed08 commit e3ac0d0
Showing 1 changed file with 14 additions and 11 deletions.
Expand Up @@ -255,17 +255,20 @@ public void SetVersionControlInfo (VersionControlDocumentInfo info)

protected abstract void CreateComponents ();

public static Cairo.Rectangle GetDiffRectangle (TextEditor editor, int startOffset, int endOffset)
public static ICollection<Cairo.Rectangle> GetDiffRectangles (TextEditor editor, int startOffset, int endOffset)
{
var point = editor.LocationToPoint (editor.Document.OffsetToLocation (startOffset), true);
Cairo.Point point2;
var line = editor.GetLineByOffset (startOffset);
if (line.Offset + line.Length < endOffset) {
point2 = new Cairo.Point ((int)(point.X + editor.TextViewMargin.CharWidth * (endOffset - startOffset)), point.Y);
} else {
point2 = editor.LocationToPoint (editor.Document.OffsetToLocation (endOffset), true);
ICollection<Cairo.Rectangle> rectangles = new List<Cairo.Rectangle> ();
var startLine = editor.GetLineByOffset (startOffset);
var endLine = editor.GetLineByOffset (endOffset);
int lineCount = endLine.LineNumber - startLine.LineNumber;
var line = startLine;
for (int i = 0; i <= lineCount; i++) {
Cairo.Point point = editor.LocationToPoint (editor.Document.OffsetToLocation (Math.Max (startOffset, line.Offset)), true);
Cairo.Point point2 = editor.LocationToPoint (editor.Document.OffsetToLocation (Math.Min (line.EndOffset, endOffset)), true);
rectangles.Add (new Cairo.Rectangle (point.X - editor.TextViewMargin.XOffset, point.Y, point2.X - point.X, editor.LineHeight));
line = line.NextLine;
}
return new Cairo.Rectangle (point.X - editor.TextViewMargin.XOffset, point.Y, point2.X - point.X, editor.LineHeight);
return rectangles;
}

Dictionary<List<Mono.TextEditor.Utils.Hunk>, Dictionary<Hunk, Tuple<List<Cairo.Rectangle>, List<Cairo.Rectangle>>>> diffCache = new Dictionary<List<Mono.TextEditor.Utils.Hunk>, Dictionary<Hunk, Tuple<List<Cairo.Rectangle>, List<Cairo.Rectangle>>>> ();
Expand All @@ -292,14 +295,14 @@ List<Cairo.Rectangle> CalculateChunkPath (TextEditor editor, List<Hunk> diff, Li
var word = words[start + i - 1];
if (endOffset != word.Offset) {
if (startOffset >= 0)
result.Add (GetDiffRectangle (editor, startOffset, endOffset));
result.AddRange (GetDiffRectangles (editor, startOffset, endOffset));
startOffset = word.Offset;
}
endOffset = word.EndOffset;
}
}
if (startOffset >= 0)
result.Add (GetDiffRectangle (editor, startOffset, endOffset));
result.AddRange (GetDiffRectangles (editor, startOffset, endOffset));
return result;
}

Expand Down

0 comments on commit e3ac0d0

Please sign in to comment.