gitk: Highlight current search hit in orange

When searching for text in the diff, and there are multiple occurrences of the search string, the current one is highlighted in orange, and the other ones in yellow. This makes it much easier to understand what happens when you then click the Search button or hit Ctrl-S repeatedly. Signed-off-by: Stefan Haller <stefan@haller-berlin.de> Signed-off-by: Paul Mackerras <paulus@samba.org>

Stefan Haller committed Sep 22, 2012 at 09:40 UTC c46149942adad1e8869cb795cc044581f2de314a
1 file changed +23 -3
gitk
+23 -3
@@ -2361,6 +2361,7 @@ proc makewindow {} {
2361 $ctext tag conf mresult -font textfontbold
2362 $ctext tag conf msep -font textfontbold
2363 $ctext tag conf found -back yellow
2364 + $ctext tag conf currentsearchhit -back orange
2365
2366 .pwbottom add .bleft
2367 if {!$use_ttk} {
@@ -2523,6 +2524,7 @@ proc makewindow {} {
2524 bind $cflist $ctxbut {pop_flist_menu %W %X %Y %x %y}
2525 bind $ctext $ctxbut {pop_diff_menu %W %X %Y %x %y}
2526 bind $ctext <Button-1> {focus %W}
2527 + bind $ctext <<Selection>> rehighlight_search_results
2528
2529 set maincursor [. cget -cursor]
2530 set textcursor [$ctext cget -cursor]
@@ -8039,7 +8041,6 @@ proc settabs {{firstab {}}} {
8041 proc incrsearch {name ix op} {
8042 global ctext searchstring searchdirn
8043
8042 - $ctext tag remove found 1.0 end
8044 if {[catch {$ctext index anchor}]} {
8045 # no anchor set, use start of selection, or of visible area
8046 set sel [$ctext tag ranges sel]
@@ -8058,8 +8059,8 @@ proc incrsearch {name ix op} {
8059 suppress_highlighting_file_for_current_scrollpos
8060 highlightfile_for_scrollpos $here
8061 }
8061 - searchmarkvisible 1
8062 }
8063 + rehighlight_search_results
8064 }
8065
8066 proc dosearch {} {
@@ -8087,6 +8088,7 @@ proc dosearch {} {
8088 set mend "$match + $mlen c"
8089 $ctext tag add sel $match $mend
8090 $ctext mark unset anchor
8091 + rehighlight_search_results
8092 }
8093 }
8094
@@ -8115,18 +8117,36 @@ proc dosearchback {} {
8117 set mend "$match + $ml c"
8118 $ctext tag add sel $match $mend
8119 $ctext mark unset anchor
8120 + rehighlight_search_results
8121 + }
8122 +}
8123 +
8124 +proc rehighlight_search_results {} {
8125 + global ctext searchstring
8126 +
8127 + $ctext tag remove found 1.0 end
8128 + $ctext tag remove currentsearchhit 1.0 end
8129 +
8130 + if {$searchstring ne {}} {
8131 + searchmarkvisible 1
8132 }
8133 }
8134
8135 proc searchmark {first last} {
8136 global ctext searchstring
8137
8138 + set sel [$ctext tag ranges sel]
8139 +
8140 set mend $first.0
8141 while {1} {
8142 set match [$ctext search -count mlen -- $searchstring $mend $last.end]
8143 if {$match eq {}} break
8144 set mend "$match + $mlen c"
8129 - $ctext tag add found $match $mend
8145 + if {$sel ne {} && [$ctext compare $match == [lindex $sel 0]]} {
8146 + $ctext tag add currentsearchhit $match $mend
8147 + } else {
8148 + $ctext tag add found $match $mend
8149 + }
8150 }
8151 }
8152