Fossil SCM

Use tab stops instead of spaces to equalize line lengths in Tk diff.

joel 2013-07-10 05:27 UTC sbsreloaded
Commit 695156c1004d3acf18e9a0eeedab8e82b73d71fb
1 file changed +14 -24
+14 -24
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -617,11 +617,11 @@
617617
@ HR_PAD_TOP 4
618618
@ HR_PAD_BTM 8
619619
@ FONTS {{DejaVu Sans Mono} Consolas Monaco fixed}
620620
@ FONT_SIZE 9
621621
@ PADX 5
622
-@ WIDTH 80
622
+@ WIDTH 81
623623
@ HEIGHT 45
624624
@ }
625625
@
626626
@ if {![namespace exists ttk]} {
627627
@ interp alias {} ::ttk::scrollbar {} ::scrollbar
@@ -661,17 +661,26 @@
661661
@ array set widths {txt 0 ln 0 mkr 0}
662662
@
663663
@ foreach c [cols] {
664664
@ while {[gets $in] ne "<pre>"} continue
665665
@ 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" : ""}]
666675
@ set str {}
667676
@ while {[set line [gets $in]] ne "</pre>"} {
668677
@ set len [string length [dehtml $line]]
669678
@ if {$len > $widths($type)} {
670679
@ set widths($type) $len
671680
@ }
672
-@ append str $line\n
681
+@ append str $line$tab\n
673682
@ }
674683
@
675684
@ set str [string range $str 0 end-1]
676685
@ set colData {}
677686
@ set re {<span class="diff([a-z]+)">([^<]*)</span>}
@@ -703,33 +712,20 @@
703712
@ $c config -state normal
704713
@ $c delete 1.0 end
705714
@ foreach {content tag} $gDiffs($idx,$c) {
706715
@ $c insert end $content $tag
707716
@ }
717
+@ $c config -state disabled
708718
@ }
709719
@
710720
@ foreach c {.lnA .lnB .mkr} {
711721
@ $c config -width $gDiffs($idx,[colType $c]-width)
712722
@ }
713723
@
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
721724
@ set width $gDiffs($idx,txt-width)
722725
@ 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)}]
731727
@ }
732728
@ }
733729
@
734730
@ proc cycleDiffs {{inc 1}} {
735731
@ global gIdx
@@ -750,17 +746,11 @@
750746
@ }
751747
@ }
752748
@
753749
@ proc copyText {c} {
754750
@ 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]]}
762752
@ clipboard clear
763753
@ clipboard append $txt
764754
@ }
765755
@
766756
@ wm withdraw .
767757
--- 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

Keyboard Shortcuts

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