Skip to content

Commit e507fd4

Browse files
committed
gitk: Improve the behaviour of the initial selection
It used to be that if you clicked on a line while gitk was still drawing stuff, it would immediately re-select the first line of the display. This fixes that. Signed-off-by: Paul Mackerras <[email protected]>
1 parent 3fc4279 commit e507fd4

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

gitk

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,7 +1671,7 @@ proc showview {n} {
16711671
global pending_select phase
16721672
global commitidx rowlaidout rowoptim linesegends
16731673
global commfd nextupdate
1674-
global selectedview
1674+
global selectedview selectfirst
16751675
global vparentlist vchildlist vdisporder vcmitlisted
16761676
global hlview selectedhlview
16771677

@@ -1689,6 +1689,9 @@ proc showview {n} {
16891689
} else {
16901690
set yscreen [expr {($ybot - $ytop) / 2}]
16911691
}
1692+
} elseif {[info exists pending_select]} {
1693+
set selid $pending_select
1694+
unset pending_select
16921695
}
16931696
unselectline
16941697
normalline
@@ -1723,7 +1726,9 @@ proc showview {n} {
17231726
.bar.view entryconf Delete* -state [expr {$n == 0? "disabled": "normal"}]
17241727

17251728
if {![info exists viewdata($n)]} {
1726-
set pending_select $selid
1729+
if {$selid ne {}} {
1730+
set pending_select $selid
1731+
}
17271732
getcommits
17281733
return
17291734
}
@@ -1757,7 +1762,8 @@ proc showview {n} {
17571762
set row 0
17581763
setcanvscroll
17591764
set yf 0
1760-
set row 0
1765+
set row {}
1766+
set selectfirst 0
17611767
if {$selid ne {} && [info exists commitrow($n,$selid)]} {
17621768
set row $commitrow($n,$selid)
17631769
# try to get the selected row in the same position on the screen
@@ -1770,7 +1776,17 @@ proc showview {n} {
17701776
}
17711777
allcanvs yview moveto $yf
17721778
drawvisible
1773-
selectline $row 0
1779+
if {$row ne {}} {
1780+
selectline $row 0
1781+
} elseif {$selid ne {}} {
1782+
set pending_select $selid
1783+
} else {
1784+
if {$numcommits > 0} {
1785+
selectline 0 0
1786+
} else {
1787+
set selectfirst 1
1788+
}
1789+
}
17741790
if {$phase ne {}} {
17751791
if {$phase eq "getcommits"} {
17761792
show_status "Reading commits..."
@@ -2407,7 +2423,7 @@ proc initlayout {} {
24072423
global nextcolor
24082424
global parentlist childlist children
24092425
global colormap rowtextx
2410-
global linesegends
2426+
global linesegends selectfirst
24112427

24122428
set numcommits 0
24132429
set displayorder {}
@@ -2427,6 +2443,7 @@ proc initlayout {} {
24272443
catch {unset rowtextx}
24282444
catch {unset idrowranges}
24292445
set linesegends {}
2446+
set selectfirst 1
24302447
}
24312448

24322449
proc setcanvscroll {} {
@@ -2495,6 +2512,7 @@ proc layoutmore {tmax} {
24952512
proc showstuff {canshow} {
24962513
global numcommits commitrow pending_select selectedline
24972514
global linesegends idrowranges idrangedrawn curview
2515+
global displayorder selectfirst
24982516

24992517
if {$numcommits == 0} {
25002518
global phase
@@ -2533,8 +2551,13 @@ proc showstuff {canshow} {
25332551
$commitrow($curview,$pending_select) < $numcommits} {
25342552
selectline $commitrow($curview,$pending_select) 1
25352553
}
2536-
if {![info exists selectedline] && ![info exists pending_select]} {
2537-
selectline 0 1
2554+
if {$selectfirst} {
2555+
if {[info exists selectedline] || [info exists pending_select]} {
2556+
set selectfirst 0
2557+
} else {
2558+
selectline 0 1
2559+
set selectfirst 0
2560+
}
25382561
}
25392562
}
25402563

@@ -3551,7 +3574,6 @@ proc drawrest {} {
35513574
global rowlaidout commitidx curview
35523575
global pending_select
35533576

3554-
set row $rowlaidout
35553577
layoutrows $rowlaidout $commitidx($curview) 1
35563578
layouttail
35573579
optimize_rows $row 0 $commitidx($curview)

0 commit comments

Comments
 (0)