@matheusbsbs / matheus-bagliano / commits / 6e5f7203de
Fork 0

[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 <gitk@tux.tmfweb.nl> and with some cleanups and simplifications... Signed-off-by: Paul Mackerras <paulus@samba.org>

Rutger Nijlunsing committed Apr 5, 2006 at 10:24 UTC 6e5f7203de440fd46c6709a9f71a7e0641363a5c
1 file changed +69 -6
gitk
+69 -6
@@ -504,12 +504,20 @@ proc makewindow {rargs} {
504 bindall <ButtonRelease-5> "allcanvs yview scroll 5 units"
505 bindall <2> "canvscan mark %W %x %y"
506 bindall <B2-Motion> "canvscan dragto %W %x %y"
507 + bindkey <Home> selfirstline
508 + bindkey <End> sellastline
509 bind . <Key-Up> "selnextline -1"
510 bind . <Key-Down> "selnextline 1"
509 - bind . <Key-Right> "goforw"
510 - bind . <Key-Left> "goback"
511 - bind . <Key-Prior> "allcanvs yview scroll -1 pages"
512 - bind . <Key-Next> "allcanvs yview scroll 1 pages"
511 + bindkey <Key-Right> "goforw"
512 + bindkey <Key-Left> "goback"
513 + bind . <Key-Prior> "selnextpage -1"
514 + bind . <Key-Next> "selnextpage 1"
515 + bind . <Control-Home> "allcanvs yview moveto 0.0"
516 + bind . <Control-End> "allcanvs yview moveto 1.0"
517 + bind . <Control-Key-Up> "allcanvs yview scroll -1 units"
518 + bind . <Control-Key-Down> "allcanvs yview scroll 1 units"
519 + bind . <Control-Key-Prior> "allcanvs yview scroll -1 pages"
520 + bind . <Control-Key-Next> "allcanvs yview scroll 1 pages"
521 bindkey <Key-Delete> "$ctext yview scroll -1 pages"
522 bindkey <Key-BackSpace> "$ctext yview scroll -1 pages"
523 bindkey <Key-space> "$ctext yview scroll 1 pages"
@@ -731,12 +739,20 @@ proc keys {} {
739 Gitk key bindings:
740
741 <Ctrl-Q> Quit
742 +<Home> Move to first commit
743 +<End> Move to last commit
744 <Up>, p, i Move up one commit
745 <Down>, n, k Move down one commit
746 <Left>, z, j Go back in history list
747 <Right>, x, l Go forward in history list
738 -<Page up> Scroll commit list up one page
739 -<Page down> Scroll commit list down one page
748 +<PageUp> Move up one page in commit list
749 +<PageDown> Move down one page in commit list
750 +<Ctrl-Home> Scroll to top of commit list
751 +<Ctrl-End> Scroll to bottom of commit list
752 +<Ctrl-Up> Scroll commit list up one line
753 +<Ctrl-Down> Scroll commit list down one line
754 +<Ctrl-PageUp> Scroll commit list up one page
755 +<Ctrl-PageDown> Scroll commit list down one page
756 <Delete>, b Scroll diff view up one page
757 <Backspace> Scroll diff view up one page
758 <Space> Scroll diff view down one page
@@ -2331,6 +2347,22 @@ proc appendwithlinks {text} {
2347 $ctext tag bind link <Leave> { %W configure -cursor $curtextcursor }
2348 }
2349
2350 +proc viewnextline {dir} {
2351 + global canv linespc
2352 +
2353 + $canv delete hover
2354 + set ymax [lindex [$canv cget -scrollregion] 3]
2355 + set wnow [$canv yview]
2356 + set wtop [expr {[lindex $wnow 0] * $ymax}]
2357 + set newtop [expr {$wtop + $dir * $linespc}]
2358 + if {$newtop < 0} {
2359 + set newtop 0
2360 + } elseif {$newtop > $ymax} {
2361 + set newtop $ymax
2362 + }
2363 + allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
2364 +}
2365 +
2366 proc selectline {l isnew} {
2367 global canv canv2 canv3 ctext commitinfo selectedline
2368 global displayorder linehtag linentag linedtag
@@ -2466,6 +2498,18 @@ proc selectline {l isnew} {
2498 }
2499 }
2500
2501 +proc selfirstline {} {
2502 + unmarkmatches
2503 + selectline 0 1
2504 +}
2505 +
2506 +proc sellastline {} {
2507 + global numcommits
2508 + unmarkmatches
2509 + set l [expr {$numcommits - 1}]
2510 + selectline $l 1
2511 +}
2512 +
2513 proc selnextline {dir} {
2514 global selectedline
2515 if {![info exists selectedline]} return
@@ -2474,6 +2518,25 @@ proc selnextline {dir} {
2518 selectline $l 1
2519 }
2520
2521 +proc selnextpage {dir} {
2522 + global canv linespc selectedline numcommits
2523 +
2524 + set lpp [expr {([winfo height $canv] - 2) / $linespc}]
2525 + if {$lpp < 1} {
2526 + set lpp 1
2527 + }
2528 + allcanvs yview scroll [expr {$dir * $lpp}] units
2529 + if {![info exists selectedline]} return
2530 + set l [expr {$selectedline + $dir * $lpp}]
2531 + if {$l < 0} {
2532 + set l 0
2533 + } elseif {$l >= $numcommits} {
2534 + set l [expr $numcommits - 1]
2535 + }
2536 + unmarkmatches
2537 + selectline $l 1
2538 +}
2539 +
2540 proc unselectline {} {
2541 global selectedline
2542