Fossil SCM

Reuse scroll-related callbacks where possible instead of redefining them on a per-element basis.

stephan 2024-09-03 11:55 trunk
Commit ddeba72d13ddc126c2e9aac1708b53e743f759061fb099b28923b4cc0b7daf21
1 file changed +16 -15
+16 -15
--- src/fossil.diff.js
+++ src/fossil.diff.js
@@ -678,10 +678,21 @@
678678
};
679679
const SCROLL_LEN = 64/* pixels to scroll for keyboard events */;
680680
const keycodes = Object.assign(Object.create(null),{
681681
37/*cursor left*/: -SCROLL_LEN, 39/*cursor right*/: SCROLL_LEN
682682
});
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
+ };
683694
/**
684695
Sets up synchronized scrolling of table.splitdiff element
685696
`diff`. If passed no argument, it scans the dom for elements to
686697
initialize. The second argument is for this function's own
687698
internal use.
@@ -720,29 +731,19 @@
720731
if(!diff.classList.contains('scroller')){
721732
/* Keyboard-based scrolling requires special-case handling to
722733
ensure that we scroll the proper side of the diff when sync
723734
is off. */
724735
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));
740741
}
741742
}
742743
return this;
743744
}
744745
window.fossil.page.tweakSbsDiffs = function(){
745746
document.querySelectorAll('table.splitdiff').forEach((e)=>initTableDiff(e));
746747
};
747748
initTableDiff();
748749
}, false);
749750
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button