@matheusbsbs / matheus-bagliano / commits / 1902c2705e
Fork 0

gitk: Improve the text window search function

This makes it work a bit more smoothly, and adds a reverse-search function, for which I stole the ^R binding from the find function. Signed-off-by: Paul Mackerras <paulus@samba.org>

Paul Mackerras committed May 25, 2006 at 21:25 UTC 1902c2705e41da499fd7ed964e747cf48a0745dd
1 file changed +69 -19
gitk
+69 -19
@@ -655,7 +655,7 @@ proc makewindow {} {
655 bind . <Control-q> doquit
656 bind . <Control-f> dofind
657 bind . <Control-g> {findnext 0}
658 - bind . <Control-r> findprev
658 + bind . <Control-r> dosearchback
659 bind . <Control-s> dosearch
660 bind . <Control-equal> {incrfont 1}
661 bind . <Control-KP_Add> {incrfont 1}
@@ -4196,41 +4196,90 @@ proc nextfile {} {
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
4199 + set l [lindex [split $first .] 0]
4200 + if {![info exists smarktop] || [$ctext compare $first < $smarktop.0]} {
4201 + set smarktop $l
4202 }
4202 - if {![info exists smarkbot] || [$ctext compare $first < $smarkbot]} {
4203 - set smarkbot $first
4203 + if {![info exists smarkbot] || [$ctext compare $first < $smarkbot.0]} {
4204 + set smarkbot $l
4205 }
4206 $ctext delete $first end
4207 }
4208
4209 proc incrsearch {name ix op} {
4209 - global ctext searchstring
4210 + global ctext searchstring searchdirn
4211
4212 $ctext tag remove found 1.0 end
4213 + if {[catch {$ctext index anchor}]} {
4214 + # no anchor set, use start of selection, or of visible area
4215 + set sel [$ctext tag ranges sel]
4216 + if {$sel ne {}} {
4217 + $ctext mark set anchor [lindex $sel 0]
4218 + } elseif {$searchdirn eq "-forwards"} {
4219 + $ctext mark set anchor @0,0
4220 + } else {
4221 + $ctext mark set anchor @0,[winfo height $ctext]
4222 + }
4223 + }
4224 if {$searchstring ne {}} {
4225 + set here [$ctext search $searchdirn -- $searchstring anchor]
4226 + if {$here ne {}} {
4227 + $ctext see $here
4228 + }
4229 searchmarkvisible 1
4230 }
4231 }
4232
4233 proc dosearch {} {
4218 - global sstring ctext searchstring
4234 + global sstring ctext searchstring searchdirn
4235
4236 focus $sstring
4237 $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
4238 + set searchdirn -forwards
4239 + if {$searchstring ne {}} {
4240 + set sel [$ctext tag ranges sel]
4241 + if {$sel ne {}} {
4242 + set start "[lindex $sel 0] + 1c"
4243 + } elseif {[catch {set start [$ctext index anchor]}]} {
4244 + set start "@0,0"
4245 + }
4246 + set match [$ctext search -count mlen -- $searchstring $start]
4247 + $ctext tag remove sel 1.0 end
4248 + if {$match eq {}} {
4249 + bell
4250 + return
4251 + }
4252 + $ctext see $match
4253 + set mend "$match + $mlen c"
4254 + $ctext tag add sel $match $mend
4255 + $ctext mark unset anchor
4256 + }
4257 +}
4258 +
4259 +proc dosearchback {} {
4260 + global sstring ctext searchstring searchdirn
4261 +
4262 + focus $sstring
4263 + $sstring icursor end
4264 + set searchdirn -backwards
4265 + if {$searchstring ne {}} {
4266 + set sel [$ctext tag ranges sel]
4267 + if {$sel ne {}} {
4268 + set start [lindex $sel 0]
4269 + } elseif {[catch {set start [$ctext index anchor]}]} {
4270 + set start @0,[winfo height $ctext]
4271 + }
4272 + set match [$ctext search -backwards -count ml -- $searchstring $start]
4273 + $ctext tag remove sel 1.0 end
4274 + if {$match eq {}} {
4275 + bell
4276 + return
4277 + }
4278 + $ctext see $match
4279 + set mend "$match + $ml c"
4280 + $ctext tag add sel $match $mend
4281 + $ctext mark unset anchor
4282 }
4230 - $ctext see $match
4231 - set mend "$match + $mlen c"
4232 - $ctext tag add sel $match $mend
4233 - $ctext mark set insert $mend
4283 }
4284
4285 proc searchmark {first last} {
@@ -4268,7 +4317,7 @@ proc searchmarkvisible {doall} {
4317 }
4318
4319 proc scrolltext {f0 f1} {
4271 - global ctext smarktop smarkbot searchstring
4320 + global searchstring
4321
4322 .ctop.cdet.left.sb set $f0 $f1
4323 if {$searchstring ne {}} {
@@ -5343,6 +5392,7 @@ set fh_serial 0
5392 set highlight_names {}
5393 set nhl_names {}
5394 set highlight_paths {}
5395 +set searchdirn -forwards
5396
5397 set optim_delay 16
5398