User:Cacycle/diff.js: Difference between revisions

Content deleted Content added
1.0.10 (September 08, 2014) + .unique, optimize speed (CalculateDiff, ShortenOutput), ShortenOutput: paragraph max/min, symbols objects instead of .parsed
1.0.11 fix ShortenOutput omitting changes/html, improve bubble up
Line 3:
// ==UserScript==
// @name wDiff
// @version 1.0.1011
// @date September 08, 2014
// @description improved word-based diff library with block move detection
Line 899:
else if ( (gapStart !== null) && (text.tokens[i].link !== null) ) {
 
// bubble up,down stopas atdeep lineas breakspossible
var front = text.tokens[gapStart].prevnext;
var back = text.tokens[i].prevnext;
while (
(front !== null) && (back !== null) && (wDiff.regExpBubbleStop.test(text.tokens[front].token) === false) &&
(text.tokens[front].link !== null) && (text.tokens[back].link === null) &&
(text.tokens[front].token == text.tokens[back].token)
) {
text.tokens[back].link = text.tokens[front].link;
textLinked.tokens[ text.tokens[back].link ].link = back;
text.tokens[front].link = null;
front = text.tokens[front].prev;
back = text.tokens[back].prev;
}
 
// do not start gap with spaces or other closing characters, roll back (bubble down)
if ( (back !== null) && (front !== null) ) {
front = text.tokens[front].next;
back = text.tokens[back].next;
}
while (
(back !== null) && (front !== null) && (wDiff.regExpBubbleClosing.test(text.tokens[front].token) === true) &&
(text.tokens[front].link === null) && (text.tokens[back].link !== null) &&
(text.tokens[front].token === text.tokens[back].token)
Line 929 ⟶ 912:
front = text.tokens[front].next;
back = text.tokens[back].next;
}
 
// test baloon up, remember last line break or closing text
var frontStop = null;
var frontTest = front;
var backTest = back;
while (
if ( (backfrontTest !== null) && (frontbackTest !== null) ) {&&
(text.tokens[frontTest].link !== null) && (text.tokens[backTest].link === null) &&
(text.tokens[frontTest].token == text.tokens[backTest].token)
) {
backfrontTest = text.tokens[backfrontTest].nextprev;
frontbackTest = text.tokens[frontbackTest].nextprev;
if (wDiff.regExpBubbleStop.test(text.tokens[frontTest].token) === true) {
frontStop = front;
break;
}
(backelse !==if null) &&( (frontfrontStop !=== null) && (wDiff.regExpBubbleClosing.test(text.tokens[frontfrontTest].token) === true) &&) {
frontStop = frontTest;
}
}
 
// actually bubble up to last line break or closing text
if (frontStop !== null) {
while (
(front !== null) && (back !== null) && (front !== frontStop) &&
(text.tokens[front].link !== null) && (text.tokens[back].link === null) &&
(text.tokens[front].token == text.tokens[back].token)
) {
text.tokens[back].link = text.tokens[front].link;
textLinked.tokens[ text.tokens[back].link ].link = back;
text.tokens[front].link = null;
front = text.tokens[front].prev;
back = text.tokens[back].prev;
}
}
gapStart = null;
Line 1,336 ⟶ 1,354:
// sort blocks by new text token number and update groups
wDiff.SortBlocks(blocks, groups);
 
// convert groups to insertions/deletions if maximal block length is too short
Line 2,498 ⟶ 2,515:
if (rangeStart[i] === undefined) {
for (var j = headingBefore; j < headings.length - 1; j ++) {
if (headings[j] > tagStart) {
break;
}
if (headings[j + 1] > tagStart) {
if ( (headings[j] > tagStart - wDiff.headingBefore) && (headings[j] > rangeStartMin) ) {
Line 2,512 ⟶ 2,532:
if (rangeStart[i] === undefined) {
for (var j = paragraphBefore; j < paragraphs.length - 1; j ++) {
if (paragraphs[j] > tagStart) {
break;
}
if (paragraphs[j + 1] > tagStart - wDiff.paragraphBeforeMin) {
if ( (paragraphs[j] > tagStart - wDiff.paragraphBeforeMax) && (paragraphs[j] > rangeStartMin) ) {