{"thread":{"id":"12464","subject":"[PATCH] gitk: fix a corner case when switching views","startedAt":"2008-03-03T19:59:52Z","lastAt":"2008-03-03T19:59:52Z","messageCount":1,"participants":["Michele Ballabio"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"70838","messageId":"200803032059.52960.barra_cuda@katamail.com","threadId":"12464","inReplyTo":null,"subject":"[PATCH] gitk: fix a corner case when switching views","fromName":"Michele Ballabio","fromEmail":"barra_cuda@katamail.com","sentAt":"2008-03-03T19:59:52Z","receivedAt":"2008-03-03T19:59:52Z","isPatch":true,"sender":{"key":"barra_cuda@katamail.com","avatar":"https://avatars.githubusercontent.com/u/16371673?v=4"},"body":"Switching from a view that shows no commit (\"No commits selected\")\nto another view, back and forth, can trigger an error like:\n\n\tcan't read \"yscreen\": no such variable\n\tcan't read \"yscreen\": no such variable\n\t    while executing\n\t\"expr {[yc $row] - $yscreen}\"\n\t    (procedure \"showview\" line 91)\n\t    invoked from within\n\t\"showview 2\"\n\t    invoked from within\n\t\".#bar.#bar#view invoke active\"\n\t    (\"uplevel\" body line 1)\n\t    invoked from within\n\t\"uplevel #0 [list $w invoke active]\"\n\t    (procedure \"tk::MenuInvoke\" line 50)\n\t    invoked from within\n\t\"tk::MenuInvoke .#bar.#bar#view 1\"\n\t    (command bound to event)\n\nThis patch avoids this with a check on yscreen and ytop in procedure\nshowview.\n\nSigned-off-by: Michele Ballabio <barra_cuda@katamail.com>\n---\n gitk |   12 ++++++++----\n 1 files changed, 8 insertions(+), 4 deletions(-)\n\ndiff --git a/gitk b/gitk\nindex f1f21e9..371654f 100755\n--- a/gitk\n+++ b/gitk\n@@ -2124,11 +2124,15 @@ proc showview {n} {\n \tset row $commitrow($n,$selid)\n \t# try to get the selected row in the same position on the screen\n \tset ymax [lindex [$canv cget -scrollregion] 3]\n-\tset ytop [expr {[yc $row] - $yscreen}]\n-\tif {$ytop < 0} {\n-\t    set ytop 0\n+\tif {[info exists yscreen]} {\n+\t    set ytop [expr {[yc $row] - $yscreen}]\n+\t}\n+\tif {[info exists ytop]} {\n+\t    if {$ytop < 0} {\n+\t\tset ytop 0\n+\t    }\n+\t    set yf [expr {$ytop * 1.0 / $ymax}]\n \t}\n-\tset yf [expr {$ytop * 1.0 / $ymax}]\n     }\n     allcanvs yview moveto $yf\n     drawvisible\n-- \n1.5.4.3\n\n"}]}