gitk: Fix problems with target row stuff

Occasionally the target row stuff would scroll the display to some
uninteresting commit while reading.  There were two problems: one
was that drawvisible would set targetrow even if there was no target
previously and no row selected, and the other was that it was possible
for the target row to get pushed down past numcommits, if drawvisible
was called after rows were added but before layoutmore got run.

The first problem is fixed by just not setting targetrow/id unless
there is a selected row or they were set previously.

The second problem is fixed by updating numcommits immediately new
rows are added.  This leads to a simplification of layoutmore and
chewcommits but also means that some of the things that were done in
layoutmore now need to be done elsewhere, since layoutmore can no
longer use numcommits to know how much it has seen previously.
Hence the changes to getcommits, initlayout and setcanvscroll.

Signed-off-by: Paul Mackerras <paulus@samba.org>
This commit is contained in:
Paul Mackerras
2008-03-03 10:11:08 +11:00
parent f806f0fba8
commit ac1276ab6e

65
gitk
View File

@ -161,11 +161,12 @@ proc stop_rev_list {view} {
} }
proc getcommits {} { proc getcommits {} {
global canv curview global canv curview need_redisplay
initlayout initlayout
start_rev_list $curview start_rev_list $curview
show_status [mc "Reading commits..."] show_status [mc "Reading commits..."]
set need_redisplay 1
} }
proc updatecommits {} { proc updatecommits {} {
@ -1048,7 +1049,7 @@ proc getcommitlines {fd inst view updating} {
adjustprogress adjustprogress
} }
if {$view == $curview} { if {$view == $curview} {
run chewcommits $view run chewcommits
} }
return 0 return 0
} }
@ -1183,7 +1184,16 @@ proc getcommitlines {fd inst view updating} {
set gotsome 1 set gotsome 1
} }
if {$gotsome} { if {$gotsome} {
run chewcommits $view global numcommits hlview
if {$view == $curview} {
set numcommits $commitidx($view)
run chewcommits
}
if {[info exists hlview] && $view == $hlview} {
# we never actually get here...
run vhighlightmore
}
foreach s $scripts { foreach s $scripts {
eval $s eval $s
} }
@ -1218,13 +1228,12 @@ proc getcommitlines {fd inst view updating} {
return 2 return 2
} }
proc chewcommits {view} { proc chewcommits {} {
global curview hlview viewcomplete global curview hlview viewcomplete
global pending_select global pending_select
if {$view == $curview} {
layoutmore layoutmore
if {$viewcomplete($view)} { if {$viewcomplete($curview)} {
global commitidx varctok global commitidx varctok
global numcommits startmsecs global numcommits startmsecs
global mainheadid commitinfo nullid global mainheadid commitinfo nullid
@ -1242,10 +1251,6 @@ proc chewcommits {view} {
} }
notbusy layout notbusy layout
} }
}
if {[info exists hlview] && $view == $hlview} {
vhighlightmore
}
return 0 return 0
} }
@ -3064,6 +3069,7 @@ proc vhighlightmore {} {
} }
} }
set vhl_done $max set vhl_done $max
return 0
} }
proc askvhighlight {row id} { proc askvhighlight {row id} {
@ -3562,15 +3568,19 @@ proc initlayout {} {
set canvxmax [$canv cget -width] set canvxmax [$canv cget -width]
catch {unset colormap} catch {unset colormap}
catch {unset rowtextx} catch {unset rowtextx}
setcanvscroll
} }
proc setcanvscroll {} { proc setcanvscroll {} {
global canv canv2 canv3 numcommits linespc canvxmax canvy0 global canv canv2 canv3 numcommits linespc canvxmax canvy0
global lastscrollset lastscrollrows
set ymax [expr {$canvy0 + ($numcommits - 0.5) * $linespc + 2}] set ymax [expr {$canvy0 + ($numcommits - 0.5) * $linespc + 2}]
$canv conf -scrollregion [list 0 0 $canvxmax $ymax] $canv conf -scrollregion [list 0 0 $canvxmax $ymax]
$canv2 conf -scrollregion [list 0 0 0 $ymax] $canv2 conf -scrollregion [list 0 0 0 $ymax]
$canv3 conf -scrollregion [list 0 0 0 $ymax] $canv3 conf -scrollregion [list 0 0 0 $ymax]
set lastscrollset [clock clicks -milliseconds]
set lastscrollrows $numcommits
} }
proc visiblerows {} { proc visiblerows {} {
@ -3595,33 +3605,17 @@ proc visiblerows {} {
proc layoutmore {} { proc layoutmore {} {
global commitidx viewcomplete curview global commitidx viewcomplete curview
global numcommits pending_select selectedline curview global numcommits pending_select selectedline curview
global lastscrollset commitinterest global lastscrollset lastscrollrows commitinterest
set canshow $commitidx($curview) if {$lastscrollrows < 100 || $viewcomplete($curview) ||
if {$canshow <= $numcommits && !$viewcomplete($curview)} return [clock clicks -milliseconds] - $lastscrollset > 500} {
if {$numcommits == 0} {
allcanvs delete all
}
set r0 $numcommits
set prev $numcommits
set numcommits $canshow
set t [clock clicks -milliseconds]
if {$prev < 100 || $viewcomplete($curview) || $t - $lastscrollset > 500} {
set lastscrollset $t
setcanvscroll setcanvscroll
} }
set rows [visiblerows]
set r1 [lindex $rows 1]
if {$r1 >= $canshow} {
set r1 [expr {$canshow - 1}]
}
if {$r0 <= $r1} {
drawcommits $r0 $r1
}
if {[info exists pending_select] && if {[info exists pending_select] &&
[commitinview $pending_select $curview]} { [commitinview $pending_select $curview]} {
selectline [rowofcommit $pending_select] 1 selectline [rowofcommit $pending_select] 1
} }
drawvisible
} }
proc doshowlocalchanges {} { proc doshowlocalchanges {} {
@ -4714,13 +4708,15 @@ proc drawvisible {} {
if {[info exists selectedline] && if {[info exists selectedline] &&
$row <= $selectedline && $selectedline <= $endrow} { $row <= $selectedline && $selectedline <= $endrow} {
set targetrow $selectedline set targetrow $selectedline
} else { } elseif {[info exists targetid]} {
set targetrow [expr {int(($row + $endrow) / 2)}] set targetrow [expr {int(($row + $endrow) / 2)}]
} }
if {[info exists targetrow]} {
if {$targetrow >= $numcommits} { if {$targetrow >= $numcommits} {
set targetrow [expr {$numcommits - 1}] set targetrow [expr {$numcommits - 1}]
} }
set targetid [commitonrow $targetrow] set targetid [commitonrow $targetrow]
}
drawcommits $row $endrow drawcommits $row $endrow
} }
@ -5459,6 +5455,10 @@ proc selectline {l isnew} {
unsel_reflist unsel_reflist
stopfinding stopfinding
if {$l < 0 || $l >= $numcommits} return if {$l < 0 || $l >= $numcommits} return
set id [commitonrow $l]
set targetid $id
set targetrow $l
set y [expr {$canvy0 + $l * $linespc}] set y [expr {$canvy0 + $l * $linespc}]
set ymax [lindex [$canv cget -scrollregion] 3] set ymax [lindex [$canv cget -scrollregion] 3]
set ytop [expr {$y - $linespc - 1}] set ytop [expr {$y - $linespc - 1}]
@ -5497,15 +5497,12 @@ proc selectline {l isnew} {
make_secsel $l make_secsel $l
set id [commitonrow $l]
if {$isnew} { if {$isnew} {
addtohistory [list selbyid $id] addtohistory [list selbyid $id]
} }
set selectedline $l set selectedline $l
set currentid $id set currentid $id
set targetid $id
set targetrow $l
$sha1entry delete 0 end $sha1entry delete 0 end
$sha1entry insert 0 $id $sha1entry insert 0 $id
$sha1entry selection from 0 $sha1entry selection from 0