Skip to content
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
31 changes: 24 additions & 7 deletions src/core/operations/Diff.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ class Diff extends Operation {
"type": "boolean",
"value": false,
"hint": "Relevant for word and line"
},
{
"name": "Show +/- notation",
"type": "boolean",
"value": false
}
];
}
Expand All @@ -73,7 +78,8 @@ class Diff extends Operation {
showAdded,
showRemoved,
showSubtraction,
ignoreWhitespace
ignoreWhitespace,
showNotation
] = args,
samples = input.split(sampleDelim);
let output = "",
Expand Down Expand Up @@ -118,12 +124,23 @@ class Diff extends Operation {
}

for (let i = 0; i < diff.length; i++) {
if (diff[i].added) {
if (showAdded) output += "<ins>" + Utils.escapeHtml(diff[i].value) + "</ins>";
} else if (diff[i].removed) {
if (showRemoved) output += "<del>" + Utils.escapeHtml(diff[i].value) + "</del>";
} else if (!showSubtraction) {
output += Utils.escapeHtml(diff[i].value);
if (showNotation) {
const escapedValue = Utils.escapeHtml(diff[i].value);
if (diff[i].added) {
if (showAdded) output += "+ " + escapedValue;
} else if (diff[i].removed) {
if (showRemoved) output += "- " + escapedValue;
} else if (!showSubtraction) {
output += " " + escapedValue;
}
} else {
if (diff[i].added) {
if (showAdded) output += "<ins>" + Utils.escapeHtml(diff[i].value) + "</ins>";
} else if (diff[i].removed) {
if (showRemoved) output += "<del>" + Utils.escapeHtml(diff[i].value) + "</del>";
} else if (!showSubtraction) {
output += Utils.escapeHtml(diff[i].value);
}
}
}

Expand Down