Fossil SCM
Tk diff: Fix up scrolling code that previously assumed equal line lengths.
Commit
2e7b57fabda90eab224e9b0d03b81e9ca0e6dcb2
Parent
7e5f3062354c419…
1 file changed
+63
-20
+63
-20
| --- src/diffcmd.c | ||
| +++ src/diffcmd.c | ||
| @@ -620,11 +620,11 @@ | ||
| 620 | 620 | @ FN_FG #ffffff |
| 621 | 621 | @ FN_PAD 5 |
| 622 | 622 | @ FONTS {{DejaVu Sans Mono} Consolas Monaco fixed} |
| 623 | 623 | @ FONT_SIZE 9 |
| 624 | 624 | @ PADX 5 |
| 625 | -@ WIDTH 81 | |
| 625 | +@ WIDTH 80 | |
| 626 | 626 | @ HEIGHT 45 |
| 627 | 627 | @ } |
| 628 | 628 | @ |
| 629 | 629 | @ if {![namespace exists ttk]} { |
| 630 | 630 | @ interp alias {} ::ttk::scrollbar {} ::scrollbar |
| @@ -697,14 +697,13 @@ | ||
| 697 | 697 | @ } |
| 698 | 698 | @ } |
| 699 | 699 | @ close $in |
| 700 | 700 | @ |
| 701 | 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]) | |
| 702 | +@ set type [colType $c] | |
| 703 | +@ if {$type ne "txt"} { | |
| 704 | +@ $c config -width $widths($type) | |
| 706 | 705 | @ } |
| 707 | 706 | @ $c config -state disabled |
| 708 | 707 | @ } |
| 709 | 708 | @ return $nDiffs |
| 710 | 709 | @ } |
| @@ -730,22 +729,63 @@ | ||
| 730 | 729 | @ viewDiff [lindex $range 0] |
| 731 | 730 | @ } |
| 732 | 731 | @ } |
| 733 | 732 | @ } |
| 734 | 733 | @ |
| 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"} { | |
| 743 | 766 | @ grid $sb |
| 744 | -@ $sb set $first $last | |
| 767 | +@ eval $sb set $xview | |
| 768 | +@ } else { | |
| 769 | +@ grid remove $sb | |
| 745 | 770 | @ } |
| 746 | 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 | |
| 747 | 787 | @ } |
| 748 | 788 | @ |
| 749 | 789 | @ wm withdraw . |
| 750 | 790 | @ wm title . $CFG(TITLE) |
| 751 | 791 | @ wm iconname . $CFG(TITLE) |
| @@ -765,25 +805,25 @@ | ||
| 765 | 805 | @ Prior y {scroll -1 page} |
| 766 | 806 | @ Next y {scroll 1 page} |
| 767 | 807 | @ Home y {moveto 0} |
| 768 | 808 | @ End y {moveto 1} |
| 769 | 809 | @ } { |
| 770 | -@ bind . <$key> ".txtA ${axis}view $args; break" | |
| 810 | +@ bind . <$key> "scroll-$axis $args; break" | |
| 771 | 811 | @ bind . <Shift-$key> continue |
| 772 | 812 | @ } |
| 773 | 813 | @ |
| 774 | 814 | @ ::ttk::menubutton .files -menu .files.menu -text "Files" |
| 775 | 815 | @ menu .files.menu -tearoff 0 |
| 776 | 816 | @ |
| 777 | -@ foreach side {A B} { | |
| 817 | +@ foreach {side syncCol} {A .txtB B .txtA} { | |
| 778 | 818 | @ set ln .ln$side |
| 779 | 819 | @ text $ln |
| 780 | 820 | @ $ln tag config - -justify right |
| 781 | 821 | @ |
| 782 | 822 | @ set txt .txt$side |
| 783 | 823 | @ text $txt -width $CFG(WIDTH) -height $CFG(HEIGHT) -wrap none \ |
| 784 | -@ -xscroll {scrollSync x {.sbxA .sbxB}} | |
| 824 | +@ -xscroll "sync-x $syncCol" | |
| 785 | 825 | @ foreach tag {add rm chng} { |
| 786 | 826 | @ $txt tag config $tag -background $CFG([string toupper $tag]_BG) |
| 787 | 827 | @ $txt tag lower $tag |
| 788 | 828 | @ } |
| 789 | 829 | @ $txt tag config fn -background $CFG(FN_BG) -foreground $CFG(FN_FG) \ |
| @@ -799,22 +839,22 @@ | ||
| 799 | 839 | @ } |
| 800 | 840 | @ } |
| 801 | 841 | @ foreach c [cols] { |
| 802 | 842 | @ set keyPrefix [string toupper [colType $c]]_COL_ |
| 803 | 843 | @ $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 | |
| 805 | 845 | @ $c tag config hr -spacing1 $CFG(HR_PAD_TOP) -spacing3 $CFG(HR_PAD_BTM) \ |
| 806 | 846 | @ -foreground $CFG(HR_FG) |
| 807 | 847 | @ $c tag config fn -spacing1 $CFG(FN_PAD) -spacing3 $CFG(FN_PAD) |
| 808 | 848 | @ bindtags $c ". $c Text all" |
| 809 | 849 | @ bind $c <1> {focus %W} |
| 810 | 850 | @ } |
| 811 | 851 | @ |
| 812 | 852 | @ ::ttk::scrollbar .sby -command {.txtA yview} -orient vertical |
| 813 | 853 | @ ::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 | |
| 816 | 856 | @ |
| 817 | 857 | @ if {[readDiffs $cmd] == 0} { |
| 818 | 858 | @ tk_messageBox -type ok -title $CFG(TITLE) -message "No changes" |
| 819 | 859 | @ exit |
| 820 | 860 | @ } |
| @@ -823,13 +863,16 @@ | ||
| 823 | 863 | @ grid columnconfigure . 1 -weight 1 |
| 824 | 864 | @ grid columnconfigure . 4 -weight 1 |
| 825 | 865 | @ grid .files -columnspan 6 |
| 826 | 866 | @ eval grid [cols] .sby -sticky nsew |
| 827 | 867 | @ grid .sbxA -row 2 -column 0 -columnspan 2 -sticky ew |
| 868 | +@ grid .spacer -row 2 -column 2 | |
| 828 | 869 | @ grid .sbxB -row 2 -column 3 -columnspan 2 -sticky ew |
| 829 | 870 | @ |
| 830 | 871 | @ wm deiconify . |
| 872 | +@ update idletasks | |
| 873 | +@ .spacer config -height [winfo height .sbxA] | |
| 831 | 874 | ; |
| 832 | 875 | |
| 833 | 876 | /* |
| 834 | 877 | ** Show diff output in a Tcl/Tk window, in response to the --tk option |
| 835 | 878 | ** to the diff command. |
| 836 | 879 |
| --- 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 |