Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to display line numbers only on left side #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions diffview.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ var diffview = {
var newTextName = params.newTextName ? params.newTextName : "New Text";
var contextSize = params.contextSize;
var inline = (params.viewType == 0 || params.viewType == 1) ? params.viewType : 0;
var bothContainLineNumbers = params.bothContainLineNumbers != null ? params.bothContainLineNumbers : true;

if (baseTextLines == null)
throw "Cannot build diff view; baseTextLines is not defined.";
Expand Down Expand Up @@ -89,8 +90,15 @@ var diffview = {
} else {
node.appendChild(document.createElement("th"));
node.appendChild(ctelt("th", "texttitle", baseTextName));
node.appendChild(document.createElement("th"));
node.appendChild(ctelt("th", "texttitle", newTextName));
if (bothContainLineNumbers) {
node.appendChild(document.createElement("th"));
node.appendChild(ctelt("th", "texttitle", newTextName));
} else {
var child = ctelt("th", "texttitle", newTextName);
node.appendChild(child);
child.style.border="1px solid #BBC;";
}

}
tdata = [tdata];

Expand All @@ -106,10 +114,16 @@ var diffview = {
* be returned. Otherwise, tidx is returned, and two empty cells are added
* to the given row.
*/
function addCells (row, tidx, tend, textLines, change) {
function addCells (row, tidx, tend, textLines, change, addLineNumber) {
if (tidx < tend) {
row.appendChild(telt("th", (tidx + 1).toString()));
row.appendChild(ctelt("td", change, textLines[tidx].replace(/\t/g, "\u00a0\u00a0\u00a0\u00a0")));
var child = ctelt("td", change, textLines[tidx].replace(/\t/g, "\u00a0\u00a0\u00a0\u00a0"));
if (addLineNumber) {
row.appendChild(telt("th", (tidx + 1).toString()));
} else {
child.style.borderLeft="1px solid #BBC";
}

row.appendChild(child);
return tidx + 1;
} else {
row.appendChild(document.createElement("th"));
Expand Down Expand Up @@ -173,8 +187,8 @@ var diffview = {
addCellsInline(node, b++, n++, baseTextLines, change);
}
} else {
b = addCells(node, b, be, baseTextLines, change);
n = addCells(node, n, ne, newTextLines, change);
b = addCells(node, b, be, baseTextLines, change, true);
n = addCells(node, n, ne, newTextLines, change, bothContainLineNumbers);
}
}

Expand Down