Skip to content

Commit d003643

Browse files
authored
Merge pull request gitx#17 from nanotech/f/eof-newlines
Display missing newlines clearly
2 parents 7cd6590 + 74ce189 commit d003643

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

html/css/diff.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151
display:none;
5252
}
5353

54+
.diff .file .diffcontent .lines .nonewline:after {
55+
content: " \20e0\23ce";
56+
font-family: -apple-system, "Helvetica Neue", sans-serif;
57+
}
5458
.diff .file .diffcontent .lines .whitespace {
5559
background-color: rgba(255,0,0,0.5);
5660
}

html/lib/diffHighlighter.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,24 @@ var highlightDiff = function(diff, element, callbacks) {
213213
continue;
214214
}
215215

216+
var isMissingEOFNewline =
217+
lineno + 1 < lines.length &&
218+
lines[lineno + 1] == "\\ No newline at end of file";
219+
var missingEOFNewlineClass = isMissingEOFNewline ? " nonewline" : "";
220+
var wrapLine = function(cls) {
221+
return "<div " + sindex + "class='" + cls + missingEOFNewlineClass + "'>"
222+
+ l + "</div>";
223+
};
224+
216225
sindex = "index=" + lindex.toString() + " ";
217226
if (firstChar == "+") {
218227
line1 += "\n";
219228
line2 += ++hunk_start_line_2 + "\n";
220-
diffContent += "<div " + sindex + "class='addline'>" + l + "</div>";
229+
diffContent += wrapLine("addline");
221230
} else if (firstChar == "-") {
222231
line1 += ++hunk_start_line_1 + "\n";
223232
line2 += "\n";
224-
diffContent += "<div " + sindex + "class='delline'>" + l + "</div>";
233+
diffContent += wrapLine("delline");
225234
} else if (firstChar == "@") {
226235
if (header) {
227236
header = false;
@@ -234,15 +243,13 @@ var highlightDiff = function(diff, element, callbacks) {
234243
}
235244
line1 += "...\n";
236245
line2 += "...\n";
237-
diffContent += "<div " + sindex + "class='hunkheader'>" + l + "</div>";
246+
diffContent += wrapLine("hunkheader");
238247
} else if (firstChar == " ") {
239248
line1 += ++hunk_start_line_1 + "\n";
240249
line2 += ++hunk_start_line_2 + "\n";
241-
diffContent += "<div " + sindex + "class='noopline'>" + l + "</div>";
250+
diffContent += wrapLine("noopline");
242251
} else if (firstChar == "\\") {
243-
line1 += ++hunk_start_line_1 + "\n";
244-
line2 += ++hunk_start_line_2 + "\n";
245-
diffContent += "<div " + sindex + "class='markerline'>" + l + "</div>";
252+
diffContent += wrapLine("markerline");
246253
}
247254
lindex++;
248255
}

0 commit comments

Comments
 (0)