Fossil SCM
Use tab stops instead of spaces to equalize line lengths in Tk diff.
Commit
695156c1004d3acf18e9a0eeedab8e82b73d71fb
Parent
2d8f2b4e246ff96…
1 file changed
+14
-24
+14
-24
| --- src/diffcmd.c | ||
| +++ src/diffcmd.c | ||
| @@ -617,11 +617,11 @@ | ||
| 617 | 617 | @ HR_PAD_TOP 4 |
| 618 | 618 | @ HR_PAD_BTM 8 |
| 619 | 619 | @ FONTS {{DejaVu Sans Mono} Consolas Monaco fixed} |
| 620 | 620 | @ FONT_SIZE 9 |
| 621 | 621 | @ PADX 5 |
| 622 | -@ WIDTH 80 | |
| 622 | +@ WIDTH 81 | |
| 623 | 623 | @ HEIGHT 45 |
| 624 | 624 | @ } |
| 625 | 625 | @ |
| 626 | 626 | @ if {![namespace exists ttk]} { |
| 627 | 627 | @ interp alias {} ::ttk::scrollbar {} ::scrollbar |
| @@ -661,17 +661,26 @@ | ||
| 661 | 661 | @ array set widths {txt 0 ln 0 mkr 0} |
| 662 | 662 | @ |
| 663 | 663 | @ foreach c [cols] { |
| 664 | 664 | @ while {[gets $in] ne "<pre>"} continue |
| 665 | 665 | @ set type [colType $c] |
| 666 | +@ # A tab character is appended to each line in a txt column. This, | |
| 667 | +@ # along with the -tabs text widget option, allows us to equalize line | |
| 668 | +@ # lengths in order to: | |
| 669 | +@ # (a) scroll to the same horizontal position on both sides and | |
| 670 | +@ # (b) keep the horizontal scrollbars from changing position/size as | |
| 671 | +@ # you scroll vertically. | |
| 672 | +@ # To test, try "fossil diff --tk --from d7afa8f153 --to abe1030ca8" | |
| 673 | +@ # as well as its inverse. | |
| 674 | +@ set tab [expr {$type eq "txt" ? "\t" : ""}] | |
| 666 | 675 | @ set str {} |
| 667 | 676 | @ while {[set line [gets $in]] ne "</pre>"} { |
| 668 | 677 | @ set len [string length [dehtml $line]] |
| 669 | 678 | @ if {$len > $widths($type)} { |
| 670 | 679 | @ set widths($type) $len |
| 671 | 680 | @ } |
| 672 | -@ append str $line\n | |
| 681 | +@ append str $line$tab\n | |
| 673 | 682 | @ } |
| 674 | 683 | @ |
| 675 | 684 | @ set str [string range $str 0 end-1] |
| 676 | 685 | @ set colData {} |
| 677 | 686 | @ set re {<span class="diff([a-z]+)">([^<]*)</span>} |
| @@ -703,33 +712,20 @@ | ||
| 703 | 712 | @ $c config -state normal |
| 704 | 713 | @ $c delete 1.0 end |
| 705 | 714 | @ foreach {content tag} $gDiffs($idx,$c) { |
| 706 | 715 | @ $c insert end $content $tag |
| 707 | 716 | @ } |
| 717 | +@ $c config -state disabled | |
| 708 | 718 | @ } |
| 709 | 719 | @ |
| 710 | 720 | @ foreach c {.lnA .lnB .mkr} { |
| 711 | 721 | @ $c config -width $gDiffs($idx,[colType $c]-width) |
| 712 | 722 | @ } |
| 713 | 723 | @ |
| 714 | -@ # Add whitespace to equalize line lengths. This is done in order to: | |
| 715 | -@ # (a) scroll to the same horizontal position on both sides and | |
| 716 | -@ # (b) keep the horizontal scrollbars from changing position/size as | |
| 717 | -@ # you scroll vertically. | |
| 718 | -@ # To test, try "fossil diff --tk --from d7afa8f153 --to abe1030ca8" | |
| 719 | -@ # as well as its inverse. | |
| 720 | -@ regexp {\d+} [.txtA index {end -1c}] numLines | |
| 721 | 724 | @ set width $gDiffs($idx,txt-width) |
| 722 | 725 | @ foreach c {.txtA .txtB} { |
| 723 | -@ for {set ln 1} {$ln <= $numLines} {incr ln} { | |
| 724 | -@ regexp {\d+$} [$c index $ln.end] len | |
| 725 | -@ $c insert $ln.end [string repeat " " [expr {$width-$len}]] ws | |
| 726 | -@ } | |
| 727 | -@ } | |
| 728 | -@ | |
| 729 | -@ foreach c [cols] { | |
| 730 | -@ $c config -state disabled | |
| 726 | +@ $c config -tabs [expr {[font measure mono 0]*($width+1)}] | |
| 731 | 727 | @ } |
| 732 | 728 | @ } |
| 733 | 729 | @ |
| 734 | 730 | @ proc cycleDiffs {{inc 1}} { |
| 735 | 731 | @ global gIdx |
| @@ -750,17 +746,11 @@ | ||
| 750 | 746 | @ } |
| 751 | 747 | @ } |
| 752 | 748 | @ |
| 753 | 749 | @ proc copyText {c} { |
| 754 | 750 | @ set txt "" |
| 755 | -@ # Copy selection without excess trailing whitespace | |
| 756 | -@ $c tag config ws -elide 1 | |
| 757 | -@ catch { | |
| 758 | -@ $c tag add sel sel.first sel.last | |
| 759 | -@ set txt [selection get] | |
| 760 | -@ } | |
| 761 | -@ $c tag config ws -elide 0 | |
| 751 | +@ catch {set txt [string map {\t\n \n} [selection get]]} | |
| 762 | 752 | @ clipboard clear |
| 763 | 753 | @ clipboard append $txt |
| 764 | 754 | @ } |
| 765 | 755 | @ |
| 766 | 756 | @ wm withdraw . |
| 767 | 757 |
| --- src/diffcmd.c | |
| +++ src/diffcmd.c | |
| @@ -617,11 +617,11 @@ | |
| 617 | @ HR_PAD_TOP 4 |
| 618 | @ HR_PAD_BTM 8 |
| 619 | @ FONTS {{DejaVu Sans Mono} Consolas Monaco fixed} |
| 620 | @ FONT_SIZE 9 |
| 621 | @ PADX 5 |
| 622 | @ WIDTH 80 |
| 623 | @ HEIGHT 45 |
| 624 | @ } |
| 625 | @ |
| 626 | @ if {![namespace exists ttk]} { |
| 627 | @ interp alias {} ::ttk::scrollbar {} ::scrollbar |
| @@ -661,17 +661,26 @@ | |
| 661 | @ array set widths {txt 0 ln 0 mkr 0} |
| 662 | @ |
| 663 | @ foreach c [cols] { |
| 664 | @ while {[gets $in] ne "<pre>"} continue |
| 665 | @ set type [colType $c] |
| 666 | @ set str {} |
| 667 | @ while {[set line [gets $in]] ne "</pre>"} { |
| 668 | @ set len [string length [dehtml $line]] |
| 669 | @ if {$len > $widths($type)} { |
| 670 | @ set widths($type) $len |
| 671 | @ } |
| 672 | @ append str $line\n |
| 673 | @ } |
| 674 | @ |
| 675 | @ set str [string range $str 0 end-1] |
| 676 | @ set colData {} |
| 677 | @ set re {<span class="diff([a-z]+)">([^<]*)</span>} |
| @@ -703,33 +712,20 @@ | |
| 703 | @ $c config -state normal |
| 704 | @ $c delete 1.0 end |
| 705 | @ foreach {content tag} $gDiffs($idx,$c) { |
| 706 | @ $c insert end $content $tag |
| 707 | @ } |
| 708 | @ } |
| 709 | @ |
| 710 | @ foreach c {.lnA .lnB .mkr} { |
| 711 | @ $c config -width $gDiffs($idx,[colType $c]-width) |
| 712 | @ } |
| 713 | @ |
| 714 | @ # Add whitespace to equalize line lengths. This is done in order to: |
| 715 | @ # (a) scroll to the same horizontal position on both sides and |
| 716 | @ # (b) keep the horizontal scrollbars from changing position/size as |
| 717 | @ # you scroll vertically. |
| 718 | @ # To test, try "fossil diff --tk --from d7afa8f153 --to abe1030ca8" |
| 719 | @ # as well as its inverse. |
| 720 | @ regexp {\d+} [.txtA index {end -1c}] numLines |
| 721 | @ set width $gDiffs($idx,txt-width) |
| 722 | @ foreach c {.txtA .txtB} { |
| 723 | @ for {set ln 1} {$ln <= $numLines} {incr ln} { |
| 724 | @ regexp {\d+$} [$c index $ln.end] len |
| 725 | @ $c insert $ln.end [string repeat " " [expr {$width-$len}]] ws |
| 726 | @ } |
| 727 | @ } |
| 728 | @ |
| 729 | @ foreach c [cols] { |
| 730 | @ $c config -state disabled |
| 731 | @ } |
| 732 | @ } |
| 733 | @ |
| 734 | @ proc cycleDiffs {{inc 1}} { |
| 735 | @ global gIdx |
| @@ -750,17 +746,11 @@ | |
| 750 | @ } |
| 751 | @ } |
| 752 | @ |
| 753 | @ proc copyText {c} { |
| 754 | @ set txt "" |
| 755 | @ # Copy selection without excess trailing whitespace |
| 756 | @ $c tag config ws -elide 1 |
| 757 | @ catch { |
| 758 | @ $c tag add sel sel.first sel.last |
| 759 | @ set txt [selection get] |
| 760 | @ } |
| 761 | @ $c tag config ws -elide 0 |
| 762 | @ clipboard clear |
| 763 | @ clipboard append $txt |
| 764 | @ } |
| 765 | @ |
| 766 | @ wm withdraw . |
| 767 |
| --- src/diffcmd.c | |
| +++ src/diffcmd.c | |
| @@ -617,11 +617,11 @@ | |
| 617 | @ HR_PAD_TOP 4 |
| 618 | @ HR_PAD_BTM 8 |
| 619 | @ FONTS {{DejaVu Sans Mono} Consolas Monaco fixed} |
| 620 | @ FONT_SIZE 9 |
| 621 | @ PADX 5 |
| 622 | @ WIDTH 81 |
| 623 | @ HEIGHT 45 |
| 624 | @ } |
| 625 | @ |
| 626 | @ if {![namespace exists ttk]} { |
| 627 | @ interp alias {} ::ttk::scrollbar {} ::scrollbar |
| @@ -661,17 +661,26 @@ | |
| 661 | @ array set widths {txt 0 ln 0 mkr 0} |
| 662 | @ |
| 663 | @ foreach c [cols] { |
| 664 | @ while {[gets $in] ne "<pre>"} continue |
| 665 | @ set type [colType $c] |
| 666 | @ # A tab character is appended to each line in a txt column. This, |
| 667 | @ # along with the -tabs text widget option, allows us to equalize line |
| 668 | @ # lengths in order to: |
| 669 | @ # (a) scroll to the same horizontal position on both sides and |
| 670 | @ # (b) keep the horizontal scrollbars from changing position/size as |
| 671 | @ # you scroll vertically. |
| 672 | @ # To test, try "fossil diff --tk --from d7afa8f153 --to abe1030ca8" |
| 673 | @ # as well as its inverse. |
| 674 | @ set tab [expr {$type eq "txt" ? "\t" : ""}] |
| 675 | @ set str {} |
| 676 | @ while {[set line [gets $in]] ne "</pre>"} { |
| 677 | @ set len [string length [dehtml $line]] |
| 678 | @ if {$len > $widths($type)} { |
| 679 | @ set widths($type) $len |
| 680 | @ } |
| 681 | @ append str $line$tab\n |
| 682 | @ } |
| 683 | @ |
| 684 | @ set str [string range $str 0 end-1] |
| 685 | @ set colData {} |
| 686 | @ set re {<span class="diff([a-z]+)">([^<]*)</span>} |
| @@ -703,33 +712,20 @@ | |
| 712 | @ $c config -state normal |
| 713 | @ $c delete 1.0 end |
| 714 | @ foreach {content tag} $gDiffs($idx,$c) { |
| 715 | @ $c insert end $content $tag |
| 716 | @ } |
| 717 | @ $c config -state disabled |
| 718 | @ } |
| 719 | @ |
| 720 | @ foreach c {.lnA .lnB .mkr} { |
| 721 | @ $c config -width $gDiffs($idx,[colType $c]-width) |
| 722 | @ } |
| 723 | @ |
| 724 | @ set width $gDiffs($idx,txt-width) |
| 725 | @ foreach c {.txtA .txtB} { |
| 726 | @ $c config -tabs [expr {[font measure mono 0]*($width+1)}] |
| 727 | @ } |
| 728 | @ } |
| 729 | @ |
| 730 | @ proc cycleDiffs {{inc 1}} { |
| 731 | @ global gIdx |
| @@ -750,17 +746,11 @@ | |
| 746 | @ } |
| 747 | @ } |
| 748 | @ |
| 749 | @ proc copyText {c} { |
| 750 | @ set txt "" |
| 751 | @ catch {set txt [string map {\t\n \n} [selection get]]} |
| 752 | @ clipboard clear |
| 753 | @ clipboard append $txt |
| 754 | @ } |
| 755 | @ |
| 756 | @ wm withdraw . |
| 757 |