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 | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

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

(This is my first patch ever, any feedback is highly appreciated)

--- a/git-gui/git-gui.sh
+++ b/git-gui/git-gui.sh
@@ -2664,6 +2664,38 @@ 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]
+               set path [lindex $file_lists($w) 0]
+               array unset selected_paths
+               set selected_paths($path) 1
+               show_diff $path $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 +3908,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.268.g7f9c27f2f

Reply via email to