').append(
+ lineNum('old',o.base),
+ $('').html(o.base ? baseTextDom(o.base): "").addClass(o.change),
+ lineNum('old',o.head),
+ $(' | ').html(o.head ? headTextDom(o.head): "").addClass(o.change)
+ ).appendTo(tbody);
+ break;
+ case 'replace':
+ var ld = lineDiff(baseTextDom(o.base), headTextDom(o.head));
+ $(' |
').append(
+ lineNum('old',o.base),
+ $('').append(ld.base).addClass('delete'),
+ lineNum('old',o.head),
+ $(' | ').append(ld.head).addClass('insert')
+ ).appendTo(tbody);
+ break;
+ }
+ }
+ return table;
+ },
+ unified:function(){
+ var table = $('');
+ var tbody = $('').appendTo(table);
+ for(var i=0;i').html(' | | '));
+ break;
+ case 'delete':
+ case 'insert':
+ case 'equal':
+ tbody.append($('').append(
+ lineNum('old',o.base),
+ lineNum('new',o.head),
+ $('').addClass(o.change).html(o.head ? headTextDom(o.head) : baseTextDom(o.base))));
+ break;
+ case 'replace':
+ var deletes = [];
+ while(oplines[i] && oplines[i].change == 'replace'){
+ if(oplines[i].base && oplines[i].head){
+ var ld = lineDiff(baseTextDom(oplines[i].base), headTextDom(oplines[i].head));
+ tbody.append($(' | ').append(lineNum('old',oplines[i].base),'',$(' | ').append(ld.base)));
+ deletes.push($(' | ').append('',lineNum('new',oplines[i].head),$(' | ').append(ld.head)));
+ }else if(oplines[i].base){
+ tbody.append($(' | ').append(lineNum('old',oplines[i].base),'',$(' | ').html(baseTextDom(oplines[i].base))));
+ }else if(oplines[i].head){
+ deletes.push($(' | ').append('',lineNum('new',oplines[i].head),$(' | ').html(headTextDom(oplines[i].head))));
+ }
+ i++;
+ }
+ tbody.append(deletes);
+ i--;
+ break;
+ }
+ }
+ return table;
+ }
+ };
+ function lineNum(type,num){
+ var cell = $(' | ').addClass(type+'line');
+ if(num){
+ cell.attr('line-number',num);
+ }
+ return cell;
+ }
+ function lineDiff(b,n){
+ var bc = $('').html(b).children();
+ var nc = $('').html(n).children();
+ var textE = function(){ return $(this).text(); };
+ var sm = new difflib.SequenceMatcher(bc.map(textE), nc.map(textE));
+ var op = sm.get_opcodes();
+ if(op.length==1 || sm.ratio()<0.5){
+ return {base:bc,head:nc};
+ }
+ var ret = { base : [], head: []};
+ for(var i=0;i').append(bc.slice(o[1],o[2])));
+ }
+ if(o[4]!=o[3]){
+ ret.head.push($('').append(nc.slice(o[3],o[4])));
+ }
+ break;
+ }
+ }
+ return ret;
+ }
+ },
+ flatten: function(opcodes, headTextLines, baseTextLines, isIgnoreLine){
+ var ret = [];
+ for (var idx = 0; idx < opcodes.length; idx++) {
+ var code = opcodes[idx];
+ var change = code[0];
+ var b = code[1];
+ var n = code[3];
+ var rowcnt = Math.max(code[2] - b, code[4] - n);
+ for (var i = 0; i < rowcnt; i++) {
+ switch(change){
+ case 'insert':
+ ret.push({
+ change:(isIgnoreLine(headTextLines[n]) ? 'equal' : change),
+ head: ++n
+ });
+ break;
+ case 'delete':
+ ret.push({
+ change: (isIgnoreLine(baseTextLines[b]) ? 'equal' : change),
+ base: ++b
+ });
+ break;
+ case 'replace':
+ var r = {change: change};
+ if(n contextSize){
+ ret.push({
+ change:'skip',
+ start:skips[0],
+ end:skips[skips.length-contextSize]
+ });
+ }
+ ret = ret.concat(skips.splice(- contextSize));
+ ret.push(o);
+ skips = [];
+ bskip = 0;
+ }
+ }
+ if(skips.length > contextSize){
+ ret.push({
+ change:'skip',
+ start:skips[0],
+ end:skips[skips.length-contextSize]
+ });
+ }
+ return ret;
+ }
+});
diff --git a/src/main/webapp/assets/vendors/jsdifflib/diffview.css b/src/main/webapp/assets/vendors/jsdifflib/diffview.css
index 399a6c7..09454b1 100644
--- a/src/main/webapp/assets/vendors/jsdifflib/diffview.css
+++ b/src/main/webapp/assets/vendors/jsdifflib/diffview.css
@@ -77,7 +77,7 @@
background-color:#FD8
}
table.diff .delete {
- background-color:#FFDDDD;
+ background-color:#ffecec;
}
table.diff .skip {
background-color: #F8F8FF;
@@ -86,10 +86,19 @@
content: " ...";
}
table.diff .insert {
- background-color:#DDFFDD
+ background-color:#eaffea
}
table.diff th.author {
text-align:right;
border-top:1px solid #BBC;
background:#EFEFEF
}
+
+table.diff ins{
+ background-color: #a6f3a6;
+ text-decoration: none;
+}
+table.diff del{
+ background-color: #f8cbcb;
+ text-decoration: none;
+}
| |