Skip to content

Commit c461499

Browse files
stefanhallerpaulusmack
authored andcommitted
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 <[email protected]> Signed-off-by: Paul Mackerras <[email protected]>
1 parent b967135 commit c461499

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

gitk

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2361,6 +2361,7 @@ proc makewindow {} {
23612361
$ctext tag conf mresult -font textfontbold
23622362
$ctext tag conf msep -font textfontbold
23632363
$ctext tag conf found -back yellow
2364+
$ctext tag conf currentsearchhit -back orange
23642365

23652366
.pwbottom add .bleft
23662367
if {!$use_ttk} {
@@ -2523,6 +2524,7 @@ proc makewindow {} {
25232524
bind $cflist $ctxbut {pop_flist_menu %W %X %Y %x %y}
25242525
bind $ctext $ctxbut {pop_diff_menu %W %X %Y %x %y}
25252526
bind $ctext <Button-1> {focus %W}
2527+
bind $ctext <<Selection>> rehighlight_search_results
25262528

25272529
set maincursor [. cget -cursor]
25282530
set textcursor [$ctext cget -cursor]
@@ -8039,7 +8041,6 @@ proc settabs {{firstab {}}} {
80398041
proc incrsearch {name ix op} {
80408042
global ctext searchstring searchdirn
80418043

8042-
$ctext tag remove found 1.0 end
80438044
if {[catch {$ctext index anchor}]} {
80448045
# no anchor set, use start of selection, or of visible area
80458046
set sel [$ctext tag ranges sel]
@@ -8058,8 +8059,8 @@ proc incrsearch {name ix op} {
80588059
suppress_highlighting_file_for_current_scrollpos
80598060
highlightfile_for_scrollpos $here
80608061
}
8061-
searchmarkvisible 1
80628062
}
8063+
rehighlight_search_results
80638064
}
80648065

80658066
proc dosearch {} {
@@ -8087,6 +8088,7 @@ proc dosearch {} {
80878088
set mend "$match + $mlen c"
80888089
$ctext tag add sel $match $mend
80898090
$ctext mark unset anchor
8091+
rehighlight_search_results
80908092
}
80918093
}
80928094

@@ -8115,18 +8117,36 @@ proc dosearchback {} {
81158117
set mend "$match + $ml c"
81168118
$ctext tag add sel $match $mend
81178119
$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
81188132
}
81198133
}
81208134

81218135
proc searchmark {first last} {
81228136
global ctext searchstring
81238137

8138+
set sel [$ctext tag ranges sel]
8139+
81248140
set mend $first.0
81258141
while {1} {
81268142
set match [$ctext search -count mlen -- $searchstring $mend $last.end]
81278143
if {$match eq {}} break
81288144
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+
}
81308150
}
81318151
}
81328152

0 commit comments

Comments
 (0)