| | @@ -106,11 +106,11 @@ |
| 106 | 106 | getLHS ? 1 : (isSplit ? 4 : 2) |
| 107 | 107 | )+')'); |
| 108 | 108 | const m = f.rx[getStart ? 'start' : 'end'].exec(td.innerText); |
| 109 | 109 | return m ? +m[1] : undefined/*"shouldn't happen"*/; |
| 110 | 110 | }; |
| 111 | | - |
| 111 | + |
| 112 | 112 | /** |
| 113 | 113 | Installs chunk-loading controls into TR.diffskip element tr. |
| 114 | 114 | Each instance corresponds to a single TR.diffskip element. |
| 115 | 115 | |
| 116 | 116 | The goal is to base these controls roughly on github's, a good |
| | @@ -400,11 +400,10 @@ |
| 400 | 400 | if(joinTr){ |
| 401 | 401 | content.push(trNext.querySelector(selector).innerHTML); |
| 402 | 402 | } |
| 403 | 403 | td.innerHTML = content.join(''); |
| 404 | 404 | if(joinTr) D.remove(joinTr); |
| 405 | | - Diff.checkTableWidth(true); |
| 406 | 405 | this.destroy(); |
| 407 | 406 | return this; |
| 408 | 407 | }else if(this.FetchType.PrevDown===fetchType){ |
| 409 | 408 | /* Append context to previous TR. */ |
| 410 | 409 | // RHS line numbers... |
| | @@ -429,11 +428,10 @@ |
| 429 | 428 | this.destroy(); |
| 430 | 429 | }else{ |
| 431 | 430 | this.maybeReplaceButtons(); |
| 432 | 431 | this.updatePosDebug(); |
| 433 | 432 | } |
| 434 | | - Diff.checkTableWidth(true); |
| 435 | 433 | return this; |
| 436 | 434 | }else if(this.FetchType.NextUp===fetchType){ |
| 437 | 435 | /* Prepend content to next TR. */ |
| 438 | 436 | // RHS line numbers... |
| 439 | 437 | if(doAppend){ |
| | @@ -458,11 +456,10 @@ |
| 458 | 456 | this.destroy(); |
| 459 | 457 | }else{ |
| 460 | 458 | this.maybeReplaceButtons(); |
| 461 | 459 | this.updatePosDebug(); |
| 462 | 460 | } |
| 463 | | - Diff.checkTableWidth(true); |
| 464 | 461 | return this; |
| 465 | 462 | }else{ |
| 466 | 463 | throw new Error("Unexpected 'fetchType' value."); |
| 467 | 464 | } |
| 468 | 465 | }, |
| | @@ -623,139 +620,5 @@ |
| 623 | 620 | }); |
| 624 | 621 | return F; |
| 625 | 622 | }; |
| 626 | 623 | Diff.setupDiffContextLoad(); |
| 627 | 624 | }); |
| 628 | | - |
| 629 | | -/* Refinements to the display of unified and side-by-side diffs. |
| 630 | | -** |
| 631 | | -** In all cases, the table columns tagged with "difftxt" are expanded, |
| 632 | | -** where possible, to fill the width of the screen. |
| 633 | | -** |
| 634 | | -** For a side-by-side diff, if either column is two wide to fit on the |
| 635 | | -** display, scrollbars are added. The scrollbars are linked, so that |
| 636 | | -** both sides scroll together. Left and right arrows also scroll. |
| 637 | | -*/ |
| 638 | | -window.fossil.onPageLoad(function(){ |
| 639 | | - const SCROLL_LEN = 25; |
| 640 | | - const F = window.fossil, D = F.dom, Diff = F.diff; |
| 641 | | - var lastWidth; |
| 642 | | - Diff.checkTableWidth = function f(force){ |
| 643 | | - if(undefined === f.contentNode){ |
| 644 | | - f.contentNode = document.querySelector('div.content'); |
| 645 | | - } |
| 646 | | - force = true; |
| 647 | | - const parentCS = window.getComputedStyle(f.contentNode); |
| 648 | | - const parentWidth = ( |
| 649 | | - //document.body.clientWidth; |
| 650 | | - //parentCS.width; |
| 651 | | - f.contentNode.clientWidth |
| 652 | | - - parseFloat(parentCS.marginLeft) - parseFloat(parentCS.marginRight) |
| 653 | | - ); |
| 654 | | - if( !force && parentWidth===lastWidth ) return this; |
| 655 | | - lastWidth = parentWidth; |
| 656 | | - let w = lastWidth*0.5 - 100; |
| 657 | | - //console.debug( "w = ",w,", lastWidth =",lastWidth," body = ",document.body.clientWidth); |
| 658 | | - if(force || !f.colsL){ |
| 659 | | - f.colsL = document.querySelectorAll('td.difftxtl pre'); |
| 660 | | - } |
| 661 | | - f.colsL.forEach(function(e){ |
| 662 | | - e.style.width = w + "px"; |
| 663 | | - e.style.maxWidth = w + "px"; |
| 664 | | - }); |
| 665 | | - if(force || !f.colsR){ |
| 666 | | - f.colsR = document.querySelectorAll('td.difftxtr pre'); |
| 667 | | - } |
| 668 | | - f.colsR.forEach(function(e){ |
| 669 | | - e.style.width = w + "px"; |
| 670 | | - e.style.maxWidth = w + "px"; |
| 671 | | - }); |
| 672 | | - if(force || !f.colsU){ |
| 673 | | - f.colsU = document.querySelectorAll('td.difftxtu pre'); |
| 674 | | - } |
| 675 | | - f.colsU.forEach(function(e){ |
| 676 | | - w = lastWidth - 3; // Outer border |
| 677 | | - var k = e.parentElement/*TD*/; |
| 678 | | - while(k = k.previousElementSibling/*TD*/) w -= k.scrollWidth; |
| 679 | | - e.style.width = w + "px"; |
| 680 | | - e.style.maxWidth = w + "px"; |
| 681 | | - }); |
| 682 | | - if(0){ // seems to be unnecessary |
| 683 | | - if(!f.allDiffs){ |
| 684 | | - f.allDiffs = document.querySelectorAll('table.diff'); |
| 685 | | - } |
| 686 | | - w = lastWidth; |
| 687 | | - f.allDiffs.forEach(function f(e){ |
| 688 | | - if(0 && !f.$){ |
| 689 | | - f.$ = e.getClientRects()[0]; |
| 690 | | - console.debug("diff table w =",w," f.$x",f.$); |
| 691 | | - w - 2*f.$.x /* left margin (assume right==left, for simplicity) */; |
| 692 | | - } |
| 693 | | - e.style.maxWidth = w + "px"; |
| 694 | | - }); |
| 695 | | - //console.debug("checkTableWidth(",force,") lastWidth =",lastWidth); |
| 696 | | - } |
| 697 | | - return this; |
| 698 | | - }; |
| 699 | | - |
| 700 | | - const scrollLeft = function(event){ |
| 701 | | - //console.debug("scrollLeft",this,event); |
| 702 | | - const table = this.parentElement/*TD*/.parentElement/*TR*/. |
| 703 | | - parentElement/*TBODY*/.parentElement/*TABLE*/; |
| 704 | | - table.$txtPres.forEach((e)=>(e===this) ? 1 : (e.scrollLeft = this.scrollLeft)); |
| 705 | | - return false; |
| 706 | | - }; |
| 707 | | - Diff.initTableDiff = function f(diff, unifiedDiffs){ |
| 708 | | - if(!diff){ |
| 709 | | - let i, diffs; |
| 710 | | - diffs = document.querySelectorAll('table.splitdiff'); |
| 711 | | - for(i=0; i<diffs.length; ++i){ |
| 712 | | - f.call(this, diffs[i], false); |
| 713 | | - } |
| 714 | | - diffs = document.querySelectorAll('table.udiff'); |
| 715 | | - for(i=0; i<diffs.length; ++i){ |
| 716 | | - f.call(this, diffs[i], true); |
| 717 | | - } |
| 718 | | - return this; |
| 719 | | - } |
| 720 | | - diff.$txtCols = diff.querySelectorAll('td.difftxt'); |
| 721 | | - diff.$txtPres = diff.querySelectorAll('td.difftxt pre'); |
| 722 | | - var width = 0; |
| 723 | | - diff.$txtPres.forEach(function(e){ |
| 724 | | - if(width < e.scrollWidth) width = e.scrollWidth; |
| 725 | | - }); |
| 726 | | - //console.debug("diff.$txtPres =",diff.$txtPres); |
| 727 | | - diff.$txtCols.forEach((e)=>e.style.width = width + 'px'); |
| 728 | | - diff.$txtPres.forEach(function(e){ |
| 729 | | - e.style.maxWidth = width + 'px'; |
| 730 | | - e.style.width = width + 'px'; |
| 731 | | - if(!unifiedDiffs && !e.classList.contains('scroller')){ |
| 732 | | - D.addClass(e, 'scroller'); |
| 733 | | - e.addEventListener('scroll', scrollLeft, false); |
| 734 | | - } |
| 735 | | - }); |
| 736 | | - if(!unifiedDiffs){ |
| 737 | | - diff.tabIndex = 0; |
| 738 | | - if(!diff.classList.contains('scroller')){ |
| 739 | | - D.addClass(diff, 'scroller'); |
| 740 | | - diff.addEventListener('keydown', function(e){ |
| 741 | | - e = e || event; |
| 742 | | - const len = {37: -SCROLL_LEN, 39: SCROLL_LEN}[e.keyCode]; |
| 743 | | - if( !len ) return; |
| 744 | | - this.$txtPres[0].scrollLeft += len; |
| 745 | | - /* ^^^ bug: if there is a 2nd column and it has a scrollbar |
| 746 | | - but txtPres[0] does not, no scrolling happens here. We need |
| 747 | | - to find the widest of txtPres and scroll that one. Example: |
| 748 | | - Checkin a7fbefee38a1c522 file diff.c */ |
| 749 | | - return false; |
| 750 | | - }, false); |
| 751 | | - } |
| 752 | | - } |
| 753 | | - return this; |
| 754 | | - } |
| 755 | | - window.fossil.page.tweakSbsDiffs = function(){ |
| 756 | | - document.querySelectorAll('table.splitdiff').forEach((e)=>Diff.initTableDiff(e)); |
| 757 | | - Diff.checkTableWidth(); |
| 758 | | - }; |
| 759 | | - Diff.initTableDiff().checkTableWidth(); |
| 760 | | - window.addEventListener('resize', F.debounce(()=>Diff.checkTableWidth())); |
| 761 | | -}, false); |
| 762 | 625 | |