feat: add +/- notation option to Diff operation

This commit is contained in:
Sushanth012 2026-04-27 21:50:08 -07:00
parent 002ed911b1
commit 7a3982e43d

View File

@ -57,6 +57,11 @@ class Diff extends Operation {
"type": "boolean", "type": "boolean",
"value": false, "value": false,
"hint": "Relevant for word and line" "hint": "Relevant for word and line"
},
{
"name": "Show +/- notation",
"type": "boolean",
"value": false
} }
]; ];
} }
@ -73,7 +78,8 @@ class Diff extends Operation {
showAdded, showAdded,
showRemoved, showRemoved,
showSubtraction, showSubtraction,
ignoreWhitespace ignoreWhitespace,
showNotation
] = args, ] = args,
samples = input.split(sampleDelim); samples = input.split(sampleDelim);
let output = "", let output = "",
@ -118,12 +124,23 @@ class Diff extends Operation {
} }
for (let i = 0; i < diff.length; i++) { for (let i = 0; i < diff.length; i++) {
if (diff[i].added) { if (showNotation) {
if (showAdded) output += "<ins>" + Utils.escapeHtml(diff[i].value) + "</ins>"; const escapedValue = Utils.escapeHtml(diff[i].value);
} else if (diff[i].removed) { if (diff[i].added) {
if (showRemoved) output += "<del>" + Utils.escapeHtml(diff[i].value) + "</del>"; if (showAdded) output += "+ " + escapedValue;
} else if (!showSubtraction) { } else if (diff[i].removed) {
output += Utils.escapeHtml(diff[i].value); 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);
}
} }
} }