From: Rutger Nijlunsing Date: Wed, 5 Apr 2006 00:24:03 +0000 (+1000) Subject: [PATCH] gitk: add key bindings for selecting first and last commit X-Git-Tag: v1.3.0-rc3~7^2~4 X-Git-Url: https://git.octo.it/?p=git.git;a=commitdiff_plain;h=6e5f7203de440fd46c6709a9f71a7e0641363a5c [PATCH] gitk: add key bindings for selecting first and last commit For a keyboard addict like me some keys are still missing from gitk. Especially a key to select a commit when no commit is selected, like just after startup. While we're at it, complete the bindings for moving the view seperately from the selected line. Currently, the up and down keys act on the selected line while pageup and pagedown act on the commits viewed. The idea is to have to normal keys change the selected line: - Home selects first commit - End selects last commit - Up selects previous commit - Down selects next commit - PageUp moves selected line one page up - PageDown moves selected line one page down ...and together with the Control key, it moves the commits view: - Control-Home views first page of commits - Control-End views last page of commits - Control-Up moves commit view one line up - Control-Down moves commit view one line down - Control-PageUp moves commit view one page up - Control-PageDown moves commit view one page down Signed-off-By: Rutger Nijlunsing and with some cleanups and simplifications... Signed-off-by: Paul Mackerras --- diff --git a/gitk b/gitk index 472c12af..8aff933e 100755 --- a/gitk +++ b/gitk @@ -504,12 +504,20 @@ proc makewindow {rargs} { bindall "allcanvs yview scroll 5 units" bindall <2> "canvscan mark %W %x %y" bindall "canvscan dragto %W %x %y" + bindkey selfirstline + bindkey sellastline bind . "selnextline -1" bind . "selnextline 1" - bind . "goforw" - bind . "goback" - bind . "allcanvs yview scroll -1 pages" - bind . "allcanvs yview scroll 1 pages" + bindkey "goforw" + bindkey "goback" + bind . "selnextpage -1" + bind . "selnextpage 1" + bind . "allcanvs yview moveto 0.0" + bind . "allcanvs yview moveto 1.0" + bind . "allcanvs yview scroll -1 units" + bind . "allcanvs yview scroll 1 units" + bind . "allcanvs yview scroll -1 pages" + bind . "allcanvs yview scroll 1 pages" bindkey "$ctext yview scroll -1 pages" bindkey "$ctext yview scroll -1 pages" bindkey "$ctext yview scroll 1 pages" @@ -731,12 +739,20 @@ proc keys {} { Gitk key bindings: Quit + Move to first commit + Move to last commit , p, i Move up one commit , n, k Move down one commit , z, j Go back in history list , x, l Go forward in history list - Scroll commit list up one page - Scroll commit list down one page + Move up one page in commit list + Move down one page in commit list + Scroll to top of commit list + Scroll to bottom of commit list + Scroll commit list up one line + Scroll commit list down one line + Scroll commit list up one page + Scroll commit list down one page , b Scroll diff view up one page Scroll diff view up one page Scroll diff view down one page @@ -2331,6 +2347,22 @@ proc appendwithlinks {text} { $ctext tag bind link { %W configure -cursor $curtextcursor } } +proc viewnextline {dir} { + global canv linespc + + $canv delete hover + set ymax [lindex [$canv cget -scrollregion] 3] + set wnow [$canv yview] + set wtop [expr {[lindex $wnow 0] * $ymax}] + set newtop [expr {$wtop + $dir * $linespc}] + if {$newtop < 0} { + set newtop 0 + } elseif {$newtop > $ymax} { + set newtop $ymax + } + allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}] +} + proc selectline {l isnew} { global canv canv2 canv3 ctext commitinfo selectedline global displayorder linehtag linentag linedtag @@ -2466,6 +2498,18 @@ proc selectline {l isnew} { } } +proc selfirstline {} { + unmarkmatches + selectline 0 1 +} + +proc sellastline {} { + global numcommits + unmarkmatches + set l [expr {$numcommits - 1}] + selectline $l 1 +} + proc selnextline {dir} { global selectedline if {![info exists selectedline]} return @@ -2474,6 +2518,25 @@ proc selnextline {dir} { selectline $l 1 } +proc selnextpage {dir} { + global canv linespc selectedline numcommits + + set lpp [expr {([winfo height $canv] - 2) / $linespc}] + if {$lpp < 1} { + set lpp 1 + } + allcanvs yview scroll [expr {$dir * $lpp}] units + if {![info exists selectedline]} return + set l [expr {$selectedline + $dir * $lpp}] + if {$l < 0} { + set l 0 + } elseif {$l >= $numcommits} { + set l [expr $numcommits - 1] + } + unmarkmatches + selectline $l 1 +} + proc unselectline {} { global selectedline