Fossil SCM
Reuse scroll-related callbacks where possible instead of redefining them on a per-element basis.
Commit
ddeba72d13ddc126c2e9aac1708b53e743f759061fb099b28923b4cc0b7daf21
Parent
c03ce0f4d43197a…
1 file changed
+16
-15
+16
-15
| --- src/fossil.diff.js | ||
| +++ src/fossil.diff.js | ||
| @@ -678,10 +678,21 @@ | ||
| 678 | 678 | }; |
| 679 | 679 | const SCROLL_LEN = 64/* pixels to scroll for keyboard events */; |
| 680 | 680 | const keycodes = Object.assign(Object.create(null),{ |
| 681 | 681 | 37/*cursor left*/: -SCROLL_LEN, 39/*cursor right*/: SCROLL_LEN |
| 682 | 682 | }); |
| 683 | + /** keydown handler for a diff element */ | |
| 684 | + const handleDiffKeydown = function(e){ | |
| 685 | + const len = keycodes[e.keyCode]; | |
| 686 | + if( !len ) return false; | |
| 687 | + if( useSync() ){ | |
| 688 | + this.$txtPres[0].scrollLeft += len; | |
| 689 | + }else if( this.$preCurrent ){ | |
| 690 | + this.$preCurrent.scrollLeft += len; | |
| 691 | + } | |
| 692 | + return false; | |
| 693 | + }; | |
| 683 | 694 | /** |
| 684 | 695 | Sets up synchronized scrolling of table.splitdiff element |
| 685 | 696 | `diff`. If passed no argument, it scans the dom for elements to |
| 686 | 697 | initialize. The second argument is for this function's own |
| 687 | 698 | internal use. |
| @@ -720,29 +731,19 @@ | ||
| 720 | 731 | if(!diff.classList.contains('scroller')){ |
| 721 | 732 | /* Keyboard-based scrolling requires special-case handling to |
| 722 | 733 | ensure that we scroll the proper side of the diff when sync |
| 723 | 734 | is off. */ |
| 724 | 735 | D.addClass(diff, 'scroller'); |
| 725 | - diff.addEventListener('keydown', function(e){ | |
| 726 | - const len = keycodes[e.keyCode]; | |
| 727 | - if( !len ) return false; | |
| 728 | - if( useSync() ){ | |
| 729 | - this.$txtPres[0].scrollLeft += len; | |
| 730 | - }else if( diff.$preCurrent ){ | |
| 731 | - this.$preCurrent.scrollLeft += len; | |
| 732 | - } | |
| 733 | - return false; | |
| 734 | - }, false); | |
| 735 | - diff.$txtPres.forEach((e)=>{ | |
| 736 | - e.addEventListener('click', function(ev){ | |
| 737 | - diff.$preCurrent = this /* NOT ev.target, which is probably a child element */; | |
| 738 | - }, false); | |
| 739 | - }) | |
| 736 | + diff.addEventListener('keydown', handleDiffKeydown, false); | |
| 737 | + const handleLRClick = function(ev){ | |
| 738 | + diff.$preCurrent = this /* NOT ev.target, which is probably a child element */; | |
| 739 | + }; | |
| 740 | + diff.$txtPres.forEach((e)=>e.addEventListener('click', handleLRClick, false)); | |
| 740 | 741 | } |
| 741 | 742 | } |
| 742 | 743 | return this; |
| 743 | 744 | } |
| 744 | 745 | window.fossil.page.tweakSbsDiffs = function(){ |
| 745 | 746 | document.querySelectorAll('table.splitdiff').forEach((e)=>initTableDiff(e)); |
| 746 | 747 | }; |
| 747 | 748 | initTableDiff(); |
| 748 | 749 | }, false); |
| 749 | 750 |
| --- src/fossil.diff.js | |
| +++ src/fossil.diff.js | |
| @@ -678,10 +678,21 @@ | |
| 678 | }; |
| 679 | const SCROLL_LEN = 64/* pixels to scroll for keyboard events */; |
| 680 | const keycodes = Object.assign(Object.create(null),{ |
| 681 | 37/*cursor left*/: -SCROLL_LEN, 39/*cursor right*/: SCROLL_LEN |
| 682 | }); |
| 683 | /** |
| 684 | Sets up synchronized scrolling of table.splitdiff element |
| 685 | `diff`. If passed no argument, it scans the dom for elements to |
| 686 | initialize. The second argument is for this function's own |
| 687 | internal use. |
| @@ -720,29 +731,19 @@ | |
| 720 | if(!diff.classList.contains('scroller')){ |
| 721 | /* Keyboard-based scrolling requires special-case handling to |
| 722 | ensure that we scroll the proper side of the diff when sync |
| 723 | is off. */ |
| 724 | D.addClass(diff, 'scroller'); |
| 725 | diff.addEventListener('keydown', function(e){ |
| 726 | const len = keycodes[e.keyCode]; |
| 727 | if( !len ) return false; |
| 728 | if( useSync() ){ |
| 729 | this.$txtPres[0].scrollLeft += len; |
| 730 | }else if( diff.$preCurrent ){ |
| 731 | this.$preCurrent.scrollLeft += len; |
| 732 | } |
| 733 | return false; |
| 734 | }, false); |
| 735 | diff.$txtPres.forEach((e)=>{ |
| 736 | e.addEventListener('click', function(ev){ |
| 737 | diff.$preCurrent = this /* NOT ev.target, which is probably a child element */; |
| 738 | }, false); |
| 739 | }) |
| 740 | } |
| 741 | } |
| 742 | return this; |
| 743 | } |
| 744 | window.fossil.page.tweakSbsDiffs = function(){ |
| 745 | document.querySelectorAll('table.splitdiff').forEach((e)=>initTableDiff(e)); |
| 746 | }; |
| 747 | initTableDiff(); |
| 748 | }, false); |
| 749 |
| --- src/fossil.diff.js | |
| +++ src/fossil.diff.js | |
| @@ -678,10 +678,21 @@ | |
| 678 | }; |
| 679 | const SCROLL_LEN = 64/* pixels to scroll for keyboard events */; |
| 680 | const keycodes = Object.assign(Object.create(null),{ |
| 681 | 37/*cursor left*/: -SCROLL_LEN, 39/*cursor right*/: SCROLL_LEN |
| 682 | }); |
| 683 | /** keydown handler for a diff element */ |
| 684 | const handleDiffKeydown = function(e){ |
| 685 | const len = keycodes[e.keyCode]; |
| 686 | if( !len ) return false; |
| 687 | if( useSync() ){ |
| 688 | this.$txtPres[0].scrollLeft += len; |
| 689 | }else if( this.$preCurrent ){ |
| 690 | this.$preCurrent.scrollLeft += len; |
| 691 | } |
| 692 | return false; |
| 693 | }; |
| 694 | /** |
| 695 | Sets up synchronized scrolling of table.splitdiff element |
| 696 | `diff`. If passed no argument, it scans the dom for elements to |
| 697 | initialize. The second argument is for this function's own |
| 698 | internal use. |
| @@ -720,29 +731,19 @@ | |
| 731 | if(!diff.classList.contains('scroller')){ |
| 732 | /* Keyboard-based scrolling requires special-case handling to |
| 733 | ensure that we scroll the proper side of the diff when sync |
| 734 | is off. */ |
| 735 | D.addClass(diff, 'scroller'); |
| 736 | diff.addEventListener('keydown', handleDiffKeydown, false); |
| 737 | const handleLRClick = function(ev){ |
| 738 | diff.$preCurrent = this /* NOT ev.target, which is probably a child element */; |
| 739 | }; |
| 740 | diff.$txtPres.forEach((e)=>e.addEventListener('click', handleLRClick, false)); |
| 741 | } |
| 742 | } |
| 743 | return this; |
| 744 | } |
| 745 | window.fossil.page.tweakSbsDiffs = function(){ |
| 746 | document.querySelectorAll('table.splitdiff').forEach((e)=>initTableDiff(e)); |
| 747 | }; |
| 748 | initTableDiff(); |
| 749 | }, false); |
| 750 |