Fossil SCM

Tk diff: Fix up scrolling code that previously assumed equal line lengths.

joel 2013-07-13 23:10 UTC sbsreloaded
Commit 2e7b57fabda90eab224e9b0d03b81e9ca0e6dcb2
1 file changed +63 -20
+63 -20
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -620,11 +620,11 @@
620620
@ FN_FG #ffffff
621621
@ FN_PAD 5
622622
@ FONTS {{DejaVu Sans Mono} Consolas Monaco fixed}
623623
@ FONT_SIZE 9
624624
@ PADX 5
625
-@ WIDTH 81
625
+@ WIDTH 80
626626
@ HEIGHT 45
627627
@ }
628628
@
629629
@ if {![namespace exists ttk]} {
630630
@ interp alias {} ::ttk::scrollbar {} ::scrollbar
@@ -697,14 +697,13 @@
697697
@ }
698698
@ }
699699
@ close $in
700700
@
701701
@ foreach c [cols] {
702
-@ if {[colType $c] eq "txt"} {
703
-@ $c config -tabs [expr {[font measure mono 0]*($widths(txt)+1)}]
704
-@ } else {
705
-@ $c config -width $widths([colType $c])
702
+@ set type [colType $c]
703
+@ if {$type ne "txt"} {
704
+@ $c config -width $widths($type)
706705
@ }
707706
@ $c config -state disabled
708707
@ }
709708
@ return $nDiffs
710709
@ }
@@ -730,22 +729,63 @@
730729
@ viewDiff [lindex $range 0]
731730
@ }
732731
@ }
733732
@ }
734733
@
735
-@ proc scrollSync {axis sbs first last} {
736
-@ foreach c [cols] {
737
-@ $c ${axis}view moveto $first
738
-@ }
739
-@ foreach sb $sbs {
740
-@ if {$first <= 0 && $last >= 1} {
741
-@ grid remove $sb
742
-@ } else {
734
+@ proc xvis {col} {
735
+@ set view [$col xview]
736
+@ return [expr {[lindex $view 1]-[lindex $view 0]}]
737
+@ }
738
+@
739
+@ proc scroll-x {args} {
740
+@ set c .txt[expr {[xvis .txtA] < [xvis .txtB] ? "A" : "B"}]
741
+@ eval $c xview $args
742
+@ }
743
+@
744
+@ interp alias {} scroll-y {} .txtA yview
745
+@
746
+@ proc noop {args} {}
747
+@
748
+@ proc enableSync {axis} {
749
+@ update idletasks
750
+@ interp alias {} sync-$axis {}
751
+@ rename _sync-$axis sync-$axis
752
+@ }
753
+@
754
+@ proc disableSync {axis} {
755
+@ rename sync-$axis _sync-$axis
756
+@ interp alias {} sync-$axis {} noop
757
+@ }
758
+@
759
+@ proc sync-x {col first last} {
760
+@ disableSync x
761
+@ $col xview moveto [expr {$first*[xvis $col]/($last-$first)}]
762
+@ foreach side {A B} {
763
+@ set sb .sbx$side
764
+@ set xview [.txt$side xview]
765
+@ if {$xview ne "0.0 1.0"} {
743766
@ grid $sb
744
-@ $sb set $first $last
767
+@ eval $sb set $xview
768
+@ } else {
769
+@ grid remove $sb
745770
@ }
746771
@ }
772
+@ enableSync x
773
+@ }
774
+@
775
+@ proc sync-y {first last} {
776
+@ disableSync y
777
+@ foreach c [cols] {
778
+@ $c yview moveto $first
779
+@ }
780
+@ if {$first > 0 || $last < 1} {
781
+@ grid .sby
782
+@ .sby set $first $last
783
+@ } else {
784
+@ grid remove .sby
785
+@ }
786
+@ enableSync y
747787
@ }
748788
@
749789
@ wm withdraw .
750790
@ wm title . $CFG(TITLE)
751791
@ wm iconname . $CFG(TITLE)
@@ -765,25 +805,25 @@
765805
@ Prior y {scroll -1 page}
766806
@ Next y {scroll 1 page}
767807
@ Home y {moveto 0}
768808
@ End y {moveto 1}
769809
@ } {
770
-@ bind . <$key> ".txtA ${axis}view $args; break"
810
+@ bind . <$key> "scroll-$axis $args; break"
771811
@ bind . <Shift-$key> continue
772812
@ }
773813
@
774814
@ ::ttk::menubutton .files -menu .files.menu -text "Files"
775815
@ menu .files.menu -tearoff 0
776816
@
777
-@ foreach side {A B} {
817
+@ foreach {side syncCol} {A .txtB B .txtA} {
778818
@ set ln .ln$side
779819
@ text $ln
780820
@ $ln tag config - -justify right
781821
@
782822
@ set txt .txt$side
783823
@ text $txt -width $CFG(WIDTH) -height $CFG(HEIGHT) -wrap none \
784
-@ -xscroll {scrollSync x {.sbxA .sbxB}}
824
+@ -xscroll "sync-x $syncCol"
785825
@ foreach tag {add rm chng} {
786826
@ $txt tag config $tag -background $CFG([string toupper $tag]_BG)
787827
@ $txt tag lower $tag
788828
@ }
789829
@ $txt tag config fn -background $CFG(FN_BG) -foreground $CFG(FN_FG) \
@@ -799,22 +839,22 @@
799839
@ }
800840
@ }
801841
@ foreach c [cols] {
802842
@ set keyPrefix [string toupper [colType $c]]_COL_
803843
@ $c config -bg $CFG(${keyPrefix}BG) -fg $CFG(${keyPrefix}FG) -borderwidth 0 \
804
-@ -font mono -padx $CFG(PADX) -insertontime 0 -yscroll {scrollSync y .sby}
844
+@ -font mono -padx $CFG(PADX) -yscroll sync-y
805845
@ $c tag config hr -spacing1 $CFG(HR_PAD_TOP) -spacing3 $CFG(HR_PAD_BTM) \
806846
@ -foreground $CFG(HR_FG)
807847
@ $c tag config fn -spacing1 $CFG(FN_PAD) -spacing3 $CFG(FN_PAD)
808848
@ bindtags $c ". $c Text all"
809849
@ bind $c <1> {focus %W}
810850
@ }
811851
@
812852
@ ::ttk::scrollbar .sby -command {.txtA yview} -orient vertical
813853
@ ::ttk::scrollbar .sbxA -command {.txtA xview} -orient horizontal
814
-@ ::ttk::scrollbar .sbxB -command {.txtA xview} -orient horizontal
815
-@
854
+@ ::ttk::scrollbar .sbxB -command {.txtB xview} -orient horizontal
855
+@ frame .spacer
816856
@
817857
@ if {[readDiffs $cmd] == 0} {
818858
@ tk_messageBox -type ok -title $CFG(TITLE) -message "No changes"
819859
@ exit
820860
@ }
@@ -823,13 +863,16 @@
823863
@ grid columnconfigure . 1 -weight 1
824864
@ grid columnconfigure . 4 -weight 1
825865
@ grid .files -columnspan 6
826866
@ eval grid [cols] .sby -sticky nsew
827867
@ grid .sbxA -row 2 -column 0 -columnspan 2 -sticky ew
868
+@ grid .spacer -row 2 -column 2
828869
@ grid .sbxB -row 2 -column 3 -columnspan 2 -sticky ew
829870
@
830871
@ wm deiconify .
872
+@ update idletasks
873
+@ .spacer config -height [winfo height .sbxA]
831874
;
832875
833876
/*
834877
** Show diff output in a Tcl/Tk window, in response to the --tk option
835878
** to the diff command.
836879
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -620,11 +620,11 @@
620 @ FN_FG #ffffff
621 @ FN_PAD 5
622 @ FONTS {{DejaVu Sans Mono} Consolas Monaco fixed}
623 @ FONT_SIZE 9
624 @ PADX 5
625 @ WIDTH 81
626 @ HEIGHT 45
627 @ }
628 @
629 @ if {![namespace exists ttk]} {
630 @ interp alias {} ::ttk::scrollbar {} ::scrollbar
@@ -697,14 +697,13 @@
697 @ }
698 @ }
699 @ close $in
700 @
701 @ foreach c [cols] {
702 @ if {[colType $c] eq "txt"} {
703 @ $c config -tabs [expr {[font measure mono 0]*($widths(txt)+1)}]
704 @ } else {
705 @ $c config -width $widths([colType $c])
706 @ }
707 @ $c config -state disabled
708 @ }
709 @ return $nDiffs
710 @ }
@@ -730,22 +729,63 @@
730 @ viewDiff [lindex $range 0]
731 @ }
732 @ }
733 @ }
734 @
735 @ proc scrollSync {axis sbs first last} {
736 @ foreach c [cols] {
737 @ $c ${axis}view moveto $first
738 @ }
739 @ foreach sb $sbs {
740 @ if {$first <= 0 && $last >= 1} {
741 @ grid remove $sb
742 @ } else {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
743 @ grid $sb
744 @ $sb set $first $last
 
 
745 @ }
746 @ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
747 @ }
748 @
749 @ wm withdraw .
750 @ wm title . $CFG(TITLE)
751 @ wm iconname . $CFG(TITLE)
@@ -765,25 +805,25 @@
765 @ Prior y {scroll -1 page}
766 @ Next y {scroll 1 page}
767 @ Home y {moveto 0}
768 @ End y {moveto 1}
769 @ } {
770 @ bind . <$key> ".txtA ${axis}view $args; break"
771 @ bind . <Shift-$key> continue
772 @ }
773 @
774 @ ::ttk::menubutton .files -menu .files.menu -text "Files"
775 @ menu .files.menu -tearoff 0
776 @
777 @ foreach side {A B} {
778 @ set ln .ln$side
779 @ text $ln
780 @ $ln tag config - -justify right
781 @
782 @ set txt .txt$side
783 @ text $txt -width $CFG(WIDTH) -height $CFG(HEIGHT) -wrap none \
784 @ -xscroll {scrollSync x {.sbxA .sbxB}}
785 @ foreach tag {add rm chng} {
786 @ $txt tag config $tag -background $CFG([string toupper $tag]_BG)
787 @ $txt tag lower $tag
788 @ }
789 @ $txt tag config fn -background $CFG(FN_BG) -foreground $CFG(FN_FG) \
@@ -799,22 +839,22 @@
799 @ }
800 @ }
801 @ foreach c [cols] {
802 @ set keyPrefix [string toupper [colType $c]]_COL_
803 @ $c config -bg $CFG(${keyPrefix}BG) -fg $CFG(${keyPrefix}FG) -borderwidth 0 \
804 @ -font mono -padx $CFG(PADX) -insertontime 0 -yscroll {scrollSync y .sby}
805 @ $c tag config hr -spacing1 $CFG(HR_PAD_TOP) -spacing3 $CFG(HR_PAD_BTM) \
806 @ -foreground $CFG(HR_FG)
807 @ $c tag config fn -spacing1 $CFG(FN_PAD) -spacing3 $CFG(FN_PAD)
808 @ bindtags $c ". $c Text all"
809 @ bind $c <1> {focus %W}
810 @ }
811 @
812 @ ::ttk::scrollbar .sby -command {.txtA yview} -orient vertical
813 @ ::ttk::scrollbar .sbxA -command {.txtA xview} -orient horizontal
814 @ ::ttk::scrollbar .sbxB -command {.txtA xview} -orient horizontal
815 @
816 @
817 @ if {[readDiffs $cmd] == 0} {
818 @ tk_messageBox -type ok -title $CFG(TITLE) -message "No changes"
819 @ exit
820 @ }
@@ -823,13 +863,16 @@
823 @ grid columnconfigure . 1 -weight 1
824 @ grid columnconfigure . 4 -weight 1
825 @ grid .files -columnspan 6
826 @ eval grid [cols] .sby -sticky nsew
827 @ grid .sbxA -row 2 -column 0 -columnspan 2 -sticky ew
 
828 @ grid .sbxB -row 2 -column 3 -columnspan 2 -sticky ew
829 @
830 @ wm deiconify .
 
 
831 ;
832
833 /*
834 ** Show diff output in a Tcl/Tk window, in response to the --tk option
835 ** to the diff command.
836
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -620,11 +620,11 @@
620 @ FN_FG #ffffff
621 @ FN_PAD 5
622 @ FONTS {{DejaVu Sans Mono} Consolas Monaco fixed}
623 @ FONT_SIZE 9
624 @ PADX 5
625 @ WIDTH 80
626 @ HEIGHT 45
627 @ }
628 @
629 @ if {![namespace exists ttk]} {
630 @ interp alias {} ::ttk::scrollbar {} ::scrollbar
@@ -697,14 +697,13 @@
697 @ }
698 @ }
699 @ close $in
700 @
701 @ foreach c [cols] {
702 @ set type [colType $c]
703 @ if {$type ne "txt"} {
704 @ $c config -width $widths($type)
 
705 @ }
706 @ $c config -state disabled
707 @ }
708 @ return $nDiffs
709 @ }
@@ -730,22 +729,63 @@
729 @ viewDiff [lindex $range 0]
730 @ }
731 @ }
732 @ }
733 @
734 @ proc xvis {col} {
735 @ set view [$col xview]
736 @ return [expr {[lindex $view 1]-[lindex $view 0]}]
737 @ }
738 @
739 @ proc scroll-x {args} {
740 @ set c .txt[expr {[xvis .txtA] < [xvis .txtB] ? "A" : "B"}]
741 @ eval $c xview $args
742 @ }
743 @
744 @ interp alias {} scroll-y {} .txtA yview
745 @
746 @ proc noop {args} {}
747 @
748 @ proc enableSync {axis} {
749 @ update idletasks
750 @ interp alias {} sync-$axis {}
751 @ rename _sync-$axis sync-$axis
752 @ }
753 @
754 @ proc disableSync {axis} {
755 @ rename sync-$axis _sync-$axis
756 @ interp alias {} sync-$axis {} noop
757 @ }
758 @
759 @ proc sync-x {col first last} {
760 @ disableSync x
761 @ $col xview moveto [expr {$first*[xvis $col]/($last-$first)}]
762 @ foreach side {A B} {
763 @ set sb .sbx$side
764 @ set xview [.txt$side xview]
765 @ if {$xview ne "0.0 1.0"} {
766 @ grid $sb
767 @ eval $sb set $xview
768 @ } else {
769 @ grid remove $sb
770 @ }
771 @ }
772 @ enableSync x
773 @ }
774 @
775 @ proc sync-y {first last} {
776 @ disableSync y
777 @ foreach c [cols] {
778 @ $c yview moveto $first
779 @ }
780 @ if {$first > 0 || $last < 1} {
781 @ grid .sby
782 @ .sby set $first $last
783 @ } else {
784 @ grid remove .sby
785 @ }
786 @ enableSync y
787 @ }
788 @
789 @ wm withdraw .
790 @ wm title . $CFG(TITLE)
791 @ wm iconname . $CFG(TITLE)
@@ -765,25 +805,25 @@
805 @ Prior y {scroll -1 page}
806 @ Next y {scroll 1 page}
807 @ Home y {moveto 0}
808 @ End y {moveto 1}
809 @ } {
810 @ bind . <$key> "scroll-$axis $args; break"
811 @ bind . <Shift-$key> continue
812 @ }
813 @
814 @ ::ttk::menubutton .files -menu .files.menu -text "Files"
815 @ menu .files.menu -tearoff 0
816 @
817 @ foreach {side syncCol} {A .txtB B .txtA} {
818 @ set ln .ln$side
819 @ text $ln
820 @ $ln tag config - -justify right
821 @
822 @ set txt .txt$side
823 @ text $txt -width $CFG(WIDTH) -height $CFG(HEIGHT) -wrap none \
824 @ -xscroll "sync-x $syncCol"
825 @ foreach tag {add rm chng} {
826 @ $txt tag config $tag -background $CFG([string toupper $tag]_BG)
827 @ $txt tag lower $tag
828 @ }
829 @ $txt tag config fn -background $CFG(FN_BG) -foreground $CFG(FN_FG) \
@@ -799,22 +839,22 @@
839 @ }
840 @ }
841 @ foreach c [cols] {
842 @ set keyPrefix [string toupper [colType $c]]_COL_
843 @ $c config -bg $CFG(${keyPrefix}BG) -fg $CFG(${keyPrefix}FG) -borderwidth 0 \
844 @ -font mono -padx $CFG(PADX) -yscroll sync-y
845 @ $c tag config hr -spacing1 $CFG(HR_PAD_TOP) -spacing3 $CFG(HR_PAD_BTM) \
846 @ -foreground $CFG(HR_FG)
847 @ $c tag config fn -spacing1 $CFG(FN_PAD) -spacing3 $CFG(FN_PAD)
848 @ bindtags $c ". $c Text all"
849 @ bind $c <1> {focus %W}
850 @ }
851 @
852 @ ::ttk::scrollbar .sby -command {.txtA yview} -orient vertical
853 @ ::ttk::scrollbar .sbxA -command {.txtA xview} -orient horizontal
854 @ ::ttk::scrollbar .sbxB -command {.txtB xview} -orient horizontal
855 @ frame .spacer
856 @
857 @ if {[readDiffs $cmd] == 0} {
858 @ tk_messageBox -type ok -title $CFG(TITLE) -message "No changes"
859 @ exit
860 @ }
@@ -823,13 +863,16 @@
863 @ grid columnconfigure . 1 -weight 1
864 @ grid columnconfigure . 4 -weight 1
865 @ grid .files -columnspan 6
866 @ eval grid [cols] .sby -sticky nsew
867 @ grid .sbxA -row 2 -column 0 -columnspan 2 -sticky ew
868 @ grid .spacer -row 2 -column 2
869 @ grid .sbxB -row 2 -column 3 -columnspan 2 -sticky ew
870 @
871 @ wm deiconify .
872 @ update idletasks
873 @ .spacer config -height [winfo height .sbxA]
874 ;
875
876 /*
877 ** Show diff output in a Tcl/Tk window, in response to the --tk option
878 ** to the diff command.
879

Keyboard Shortcuts

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