342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
|
on this.isSplit), but does not fill it with any information nor
inject it into the table (it doesn't know where to do
so). Returns an object containing the TR element and various TD
elements which will likely be needed by the routine which
called this. See this code for details.
*/
newTR: function(){
const tr = D.addClass(D.tr(),'fetched'), rc = {
tr,
preLnL: D.pre(),
preLnR: D.pre()
};
if(this.isSplit){
D.append(D.addClass( D.td(tr), 'diffln', 'difflnl' ), rc.preLnL);
rc.preTxtL = D.pre();
D.append(D.addClass( D.td(tr), 'difftxt', 'difftxtl' ), rc.preTxtL);
D.addClass( D.td(tr), 'diffsep' );
D.append(D.addClass( D.td(tr), 'diffln', 'difflnr' ), rc.preLnR);
rc.preTxtR = D.pre();
D.append(D.addClass( D.td(tr), 'difftxt', 'difftxtr' ), rc.preTxtR);
}else{
D.append(D.addClass( D.td(tr), 'diffln', 'difflnl' ), rc.preLnL);
D.append(D.addClass( D.td(tr), 'diffln', 'difflnr' ), rc.preLnR);
D.addClass( D.td(tr), 'diffsep' );
rc.preTxtU = D.pre();
D.append(D.addClass( D.td(tr), 'difftxt', 'difftxtu' ), rc.preTxtU);
}
return rc;
},
injectResponse: function(direction/*as for fetchChunk()*/,
urlParam/*from fetchChunk()*/,
lines/*response lines*/){
console.debug("Loading line range ",urlParam.from,"-",urlParam.to);
const row = this.newTR();
const lineno = [];
let i;
for( i = urlParam.from; i <= urlParam.to; ++i ){
/* TODO: space-pad numbers, but we don't know the proper length from here. */
lineno.push(i);
}
row.preLnL.innerText = lineno.join('\n')+'\n';
if(row.preTxtU){//unified diff
row.preTxtU.innerText = lines.join('\n')+'\n';
}else{//split diff
const code = lines.join('\n')+'\n';
row.preTxtL.innerText = code;
row.preTxtR.innerText = code;
}
if(0===direction){
/* Closing the whole gap between two chunks or a whole gap
at the start or end of a diff. */
let startLnR = this.pos.prev
? this.pos.prev.endRhs+1 /* Closing the whole gap between two chunks
or end-of-file gap. */
: this.pos.next.startRhs - lines.length /* start-of-file gap */;
lineno.length = 0;
for( i = startLnR; i < startLnR + lines.length; ++i ){
/* TODO? space-pad numbers, but we don't know the proper length from here. */
lineno.push(i);
}
row.preLnR.innerText = lineno.join('\n')+'\n';
this.e.tr.parentNode.insertBefore(row.tr, this.e.tr);
Diff.initTableDiff(this.e.table/*fix scrolling*/).checkTableWidth(true);
this.destroy();
return this;
}else{
console.debug("TODO: handle load of partial next/prev");
this.updatePosDebug();
}
},
fetchChunk: function(direction/*-1=prev, 1=next, 0=both*/){
/* Forewarning, this is a bit confusing: when fetching the
previous lines, we're doing so on behalf of the *next* diff
chunk (this.pos.next), and vice versa. */
if(this.$isFetching){
console.debug("Cannot load chunk while a load is pending.");
return this;
}
|
|
|
>
|
|
<
|
>
>
>
>
>
>
>
>
>
|
>
>
>
|
<
|
|
|
>
>
>
>
>
>
>
>
|
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
|
>
>
|
>
>
>
|
>
>
|
<
>
>
>
>
>
>
>
>
>
>
|
|
>
>
>
|
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
|
on this.isSplit), but does not fill it with any information nor
inject it into the table (it doesn't know where to do
so). Returns an object containing the TR element and various TD
elements which will likely be needed by the routine which
called this. See this code for details.
*/
newTR: function(){
const tr = D.tr(), rc = {
tr,
preLnL: D.pre(),
preLnR: D.pre(),
preSep: D.pre()
};
if(this.isSplit){
D.append(D.addClass( D.td(tr), 'diffln', 'difflnl' ), rc.preLnL);
rc.preTxtL = D.pre();
D.append(D.addClass( D.td(tr), 'difftxt', 'difftxtl' ), rc.preTxtL);
D.append(D.addClass( D.td(tr), 'diffsep' ), rc.preSep);
D.append(D.addClass( D.td(tr), 'diffln', 'difflnr' ), rc.preLnR);
rc.preTxtR = D.pre();
D.append(D.addClass( D.td(tr), 'difftxt', 'difftxtr' ), rc.preTxtR);
}else{
D.append(D.addClass( D.td(tr), 'diffln', 'difflnl' ), rc.preLnL);
D.append(D.addClass( D.td(tr), 'diffln', 'difflnr' ), rc.preLnR);
D.append(D.addClass( D.td(tr), 'diffsep' ), rc.preSep);
rc.preTxtU = D.pre();
D.append(D.addClass( D.td(tr), 'difftxt', 'difftxtu' ), rc.preTxtU);
}
return rc;
},
injectResponse: function(direction/*as for fetchChunk()*/,
urlParam/*from fetchChunk()*/,
lines/*response lines*/){
console.debug("Loading line range ",urlParam.from,"-",urlParam.to);
const lineno = [],
trPrev = this.e.tr.previousElementSibling,
trNext = this.e.tr.nextElementSibling,
doAppend = !!trPrev /* true to append to previous TR, else prepend to NEXT TR */;
const tr = trPrev || trNext;
if(0!==direction){
console.error("this case is not yet handled",arguments);
return this;
}
const joinTr = (0===direction && trPrev && trNext);
let i, td;
if(1){ // LHS line numbers...
const selector = '.difflnl > pre';
td = tr.querySelector(selector);
for( i = urlParam.from; i <= urlParam.to; ++i ){
lineno.push(i);
}
const lineNoTxt = lineno.join('\n')+'\n';
const content = [];
if(doAppend) content.push(td.innerHTML, lineNoTxt);
else content.push(lineNoTxt, td.innerHTML);
if(joinTr){
content.push(trNext.querySelector(selector).innerHTML);
}
td.innerHTML = content.join('');
}
if(1){// code block...
const selector = '.difftxt > pre';
td = tr.querySelectorAll(selector);
const code = D.append(D.div(),lines.join('\n')+'\n').innerText;
let joinNdx = 0;
td.forEach(function(e){
const content = [];
if(doAppend) content.push(e.innerHTML, code);
else content.push(code, e.innerHTML);
if(joinTr){
content.push(trNext.querySelectorAll(selector)[joinNdx++].innerHTML)
}
e.innerHTML = content.join('');
});
}
if(1){
// Add blank lines in (.diffsep>pre)
const selector = '.diffsep > pre';
td = tr.querySelector(selector);
for(i = 0; i < lineno.length; ++i) lineno[i] = '';
const blanks = lineno.join('\n')+'\n';
const content = [];
if(doAppend) content.push(td.innerHTML, blanks);
else content.push(blanks, td.innerHTML);
if(joinTr){
content.push(trNext.querySelector(selector).innerHTML);
}
td.innerHTML = content.join('');
}
if(0===direction){
/* Closing the whole gap between two chunks or a whole gap
at the start or end of a diff. */
let startLnR = this.pos.prev
? this.pos.prev.endRhs+1 /* Closing the whole gap between two chunks
or end-of-file gap. */
: this.pos.next.startRhs - lines.length /* start-of-file gap */;
lineno.length = 0;
for( i = startLnR; i < startLnR + lines.length; ++i ){
/* TODO? space-pad numbers, but we don't know the proper length from here. */
lineno.push(i);
}
const selector = '.difflnr > pre';
td = tr.querySelector(selector);
const lineNoTxt = lineno.join('\n')+'\n';
const content = [];
if(doAppend) content.push(td.innerHTML, lineNoTxt);
else content.push(lineNoTxt, td.innerHTML);
if(joinTr){
content.push(trNext.querySelector(selector).innerHTML);
}
td.innerHTML = content.join('');
if(joinTr){
D.remove(joinTr);
}
Diff.checkTableWidth(true);
this.destroy();
return this;
}else{
console.debug("TODO: handle load of partial next/prev");
this.updatePosDebug();
}
},
fetchChunk: function(direction/*-1=down from prev chunk,
1=up from next chunk,
0=full-gap filler for any neighoring
chunk(s)*/){
/* Forewarning, this is a bit confusing: when fetching the
previous lines, we're doing so on behalf of the *next* diff
chunk (this.pos.next), and vice versa. */
if(this.$isFetching){
console.debug("Cannot load chunk while a load is pending.");
return this;
}
|