Skip to content

Commit

Permalink
diffHighlighter.js: Record the line index as attribute.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdtsmith authored and Pieter de Bie committed Jun 21, 2009
1 parent bcc652b commit 1688c2a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions html/lib/diffHighlighter.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ var highlightDiff = function(diff, element, callbacks) {
startname = "";
endname = "";
}
for (var lineno = 0; lineno < lines.length; lineno++) {
for (var lineno = 0, lindex = 0; lineno < lines.length; lineno++) {
var l = lines[lineno];

var firstChar = l.charAt(0);
Expand Down Expand Up @@ -186,18 +186,19 @@ var highlightDiff = function(diff, element, callbacks) {
continue;
}

sindex = "index=" + lindex.toString() + " ";
if (firstChar == "+") {
// Highlight trailing whitespace
if (m = l.match(/\s+$/))
l = l.replace(/\s+$/, "<span class='whitespace'>" + m + "</span>");

line1 += "\n";
line2 += ++hunk_start_line_2 + "\n";
diffContent += "<div class='addline'>" + l + "</div>";
diffContent += "<div " + sindex + "class='addline'>" + l + "</div>";
} else if (firstChar == "-") {
line1 += ++hunk_start_line_1 + "\n";
line2 += "\n";
diffContent += "<div class='delline'>" + l + "</div>";
diffContent += "<div " + sindex + "class='delline'>" + l + "</div>";
} else if (firstChar == "@") {
if (header) {
header = false;
Expand All @@ -210,12 +211,13 @@ var highlightDiff = function(diff, element, callbacks) {
}
line1 += "...\n";
line2 += "...\n";
diffContent += "<div class='hunkheader'>" + l + "</div>";
diffContent += "<div " + sindex + "class='hunkheader'>" + l + "</div>";
} else if (firstChar == " ") {
line1 += ++hunk_start_line_1 + "\n";
line2 += ++hunk_start_line_2 + "\n";
diffContent += "<div class='noopline'>" + l + "</div>";
diffContent += "<div " + sindex + "class='noopline'>" + l + "</div>";
}
lindex++;
}

finishContent();
Expand All @@ -227,3 +229,4 @@ var highlightDiff = function(diff, element, callbacks) {
if (false)
Controller.log_("Total time:" + (new Date().getTime() - start));
}
diffContent += "<div " + sindex + "class='addline'>" + l + "</div>";

0 comments on commit 1688c2a

Please sign in to comment.