The user cannot change focus between the list of files, the diff view
and the commit message widgets without using the mouse (clicking either of
the four widgets ).

Hotkeys CTRL/CMD+number (1-4) now focuses the first file of either the
"Unstaged Changes" or "Staged Changes", the diff view or the
commit message dialog widgets, respectively. This enables the user to
select/unselect files, view the diff and create a commit in git-gui
using keyboard-only.

Signed-off-by: Birger Skogeng Pedersen <birge...@gmail.com>
---
 git-gui/git-gui.sh | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh
index 91c00e648..bdbe166f7 100755

(First timere here, any feedback is highly appreciated)

--- a/git-gui/git-gui.sh
+++ b/git-gui/git-gui.sh
@@ -2664,6 +2664,35 @@ proc show_less_context {} {
        }
 }
 
+proc select_first_path {w} {
+       global file_lists last_clicked selected_paths
+       if {[llength $file_lists($w)] > 0} {
+               focus $w
+               set last_clicked [list $w 1]
+               show_diff [lindex $file_lists($w) 0] $w
+       }
+}
+
+proc select_first_unstaged_changes_path {} {
+       global ui_workdir
+       select_first_path $ui_workdir
+}
+
+proc select_first_staged_changes_path {} {
+       global ui_index
+       select_first_path $ui_index
+}
+
+proc focus_diff {} {
+       global ui_diff
+       focus $ui_diff
+}
+
+proc focus_commit_message {} {
+       global ui_comm
+       focus $ui_comm
+}
+
 ######################################################################
 ##
 ## ui construction
@@ -3876,6 +3905,11 @@ foreach i [list $ui_index $ui_workdir] {
 }
 unset i
 
+bind . <$M1B-Key-1> {select_first_unstaged_changes_path}
+bind . <$M1B-Key-2> {select_first_staged_changes_path}
+bind . <$M1B-Key-3> {focus_diff}
+bind . <$M1B-Key-4> {focus_commit_message}
+
 set file_lists($ui_index) [list]
 set file_lists($ui_workdir) [list]
 
-- 
2.16.2.266.g75bb9601e

Reply via email to