gitk: First cut at a search function in the patch/file display window
This does incremental highlighting of matches to the search string but doesn't do true incremental search a la emacs. Signed-off-by: Paul Mackerras <paulus@samba.org>
Paul Mackerras committed
May 24, 2006 at 10:16 UTC
3ea06f9f7e10463ee52b7ed8cbe3b2728c9e662e
1 file changed
+101
-6
gitk
+101
-6
@@ -384,6 +384,7 @@ proc makewindow {} {
384
global maincursor textcursor curtextcursor
385
global rowctxmenu mergemax
386
global highlight_files highlight_names
387
+ global searchstring sstring
388
389
menu .bar
390
.bar add cascade -label "File" -menu .bar.file
@@ -542,10 +543,20 @@ proc makewindow {} {
543
panedwindow .ctop.cdet -orient horizontal
544
.ctop add .ctop.cdet
545
frame .ctop.cdet.left
546
+ frame .ctop.cdet.left.bot
547
+ pack .ctop.cdet.left.bot -side bottom -fill x
548
+ button .ctop.cdet.left.bot.search -text "Search" -command dosearch \
549
+ -font $uifont
550
+ pack .ctop.cdet.left.bot.search -side left -padx 5
551
+ set sstring .ctop.cdet.left.bot.sstring
552
+ entry $sstring -width 20 -font $textfont -textvariable searchstring
553
+ lappend entries $sstring
554
+ trace add variable searchstring write incrsearch
555
+ pack $sstring -side left -expand 1 -fill x
556
set ctext .ctop.cdet.left.ctext
557
text $ctext -bg white -state disabled -font $textfont \
558
-width $geometry(ctextw) -height $geometry(ctexth) \
548
- -yscrollcommand {.ctop.cdet.left.sb set} -wrap none
559
+ -yscrollcommand scrolltext -wrap none
560
scrollbar .ctop.cdet.left.sb -command "$ctext yview"
561
pack .ctop.cdet.left.sb -side right -fill y
562
pack $ctext -side left -fill both -expand 1
@@ -645,6 +656,7 @@ proc makewindow {} {
656
bind . <Control-f> dofind
657
bind . <Control-g> {findnext 0}
658
bind . <Control-r> findprev
659
+ bind . <Control-s> dosearch
660
bind . <Control-equal> {incrfont 1}
661
bind . <Control-KP_Add> {incrfont 1}
662
bind . <Control-minus> {incrfont -1}
@@ -3643,7 +3655,7 @@ proc selectline {l isnew} {
3655
$sha1entry selection to end
3656
3657
$ctext conf -state normal
3646
- $ctext delete 0.0 end
3658
+ clear_ctext
3659
set linknum 0
3660
set info $commitinfo($id)
3661
set date [formatdate [lindex $info 2]]
@@ -3881,7 +3893,7 @@ proc showfile {f} {
3893
fconfigure $bf -blocking 0
3894
fileevent $bf readable [list getblobline $bf $diffids]
3895
$ctext config -state normal
3884
- $ctext delete $commentend end
3896
+ clear_ctext $commentend
3897
$ctext insert end "\n"
3898
$ctext insert end "$f\n" filesep
3899
$ctext config -state disabled
@@ -4181,6 +4193,89 @@ proc nextfile {} {
4193
}
4194
}
4195
4196
+proc clear_ctext {{first 1.0}} {
4197
+ global ctext smarktop smarkbot
4198
+
4199
+ if {![info exists smarktop] || [$ctext compare $first < $smarktop]} {
4200
+ set smarktop $first
4201
+ }
4202
+ if {![info exists smarkbot] || [$ctext compare $first < $smarkbot]} {
4203
+ set smarkbot $first
4204
+ }
4205
+ $ctext delete $first end
4206
+}
4207
+
4208
+proc incrsearch {name ix op} {
4209
+ global ctext searchstring
4210
+
4211
+ $ctext tag remove found 1.0 end
4212
+ if {$searchstring ne {}} {
4213
+ searchmarkvisible 1
4214
+ }
4215
+}
4216
+
4217
+proc dosearch {} {
4218
+ global sstring ctext searchstring
4219
+
4220
+ focus $sstring
4221
+ $sstring icursor end
4222
+ $ctext tag remove sel 1.0 end
4223
+ if {$searchstring eq {}} return
4224
+ set here [$ctext index insert]
4225
+ set match [$ctext search -count mlen -- $searchstring $here]
4226
+ if {$match eq {}} {
4227
+ bell
4228
+ return
4229
+ }
4230
+ $ctext see $match
4231
+ set mend "$match + $mlen c"
4232
+ $ctext tag add sel $match $mend
4233
+ $ctext mark set insert $mend
4234
+}
4235
+
4236
+proc searchmark {first last} {
4237
+ global ctext searchstring
4238
+
4239
+ set mend $first.0
4240
+ while {1} {
4241
+ set match [$ctext search -count mlen -- $searchstring $mend $last.end]
4242
+ if {$match eq {}} break
4243
+ set mend "$match + $mlen c"
4244
+ $ctext tag add found $match $mend
4245
+ }
4246
+}
4247
+
4248
+proc searchmarkvisible {doall} {
4249
+ global ctext smarktop smarkbot
4250
+
4251
+ set topline [lindex [split [$ctext index @0,0] .] 0]
4252
+ set botline [lindex [split [$ctext index @0,[winfo height $ctext]] .] 0]
4253
+ if {$doall || $botline < $smarktop || $topline > $smarkbot} {
4254
+ # no overlap with previous
4255
+ searchmark $topline $botline
4256
+ set smarktop $topline
4257
+ set smarkbot $botline
4258
+ } else {
4259
+ if {$topline < $smarktop} {
4260
+ searchmark $topline [expr {$smarktop-1}]
4261
+ set smarktop $topline
4262
+ }
4263
+ if {$botline > $smarkbot} {
4264
+ searchmark [expr {$smarkbot+1}] $botline
4265
+ set smarkbot $botline
4266
+ }
4267
+ }
4268
+}
4269
+
4270
+proc scrolltext {f0 f1} {
4271
+ global ctext smarktop smarkbot searchstring
4272
+
4273
+ .ctop.cdet.left.sb set $f0 $f1
4274
+ if {$searchstring ne {}} {
4275
+ searchmarkvisible 0
4276
+ }
4277
+}
4278
+
4279
proc setcoords {} {
4280
global linespc charspc canvx0 canvy0 mainfont
4281
global xspc1 xspc2 lthickness
@@ -4415,7 +4510,7 @@ proc lineclick {x y id isnew} {
4510
}
4511
# fill the details pane with info about this line
4512
$ctext conf -state normal
4418
- $ctext delete 0.0 end
4513
+ clear_ctext
4514
$ctext tag conf link -foreground blue -underline 1
4515
$ctext tag bind link <Enter> { %W configure -cursor hand2 }
4516
$ctext tag bind link <Leave> { %W configure -cursor $curtextcursor }
@@ -4508,7 +4603,7 @@ proc doseldiff {oldid newid} {
4603
global commitinfo
4604
4605
$ctext conf -state normal
4511
- $ctext delete 0.0 end
4606
+ clear_ctext
4607
init_flist "Top"
4608
$ctext insert end "From "
4609
$ctext tag conf link -foreground blue -underline 1
@@ -4802,7 +4897,7 @@ proc showtag {tag isnew} {
4897
addtohistory [list showtag $tag 0]
4898
}
4899
$ctext conf -state normal
4805
- $ctext delete 0.0 end
4900
+ clear_ctext
4901
set linknum 0
4902
if {[info exists tagcontents($tag)]} {
4903
set text $tagcontents($tag)