git-gui: add hotkeys to set widget focus
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). With this patch, the user may set ui focus to the previously selected path in either the "Unstaged Changes" or "Staged Changes" widgets, using ALT+1 or ALT+2. The user may also set the ui focus to the diff view widget with ALT+3, or to the commit message widget with ALT+4. 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 <birger.sp@gmail.com> Signed-off-by: Pratyush Yadav <me@yadavpratyush.com>
Birger Skogeng Pedersen committed
Sep 4, 2019 at 16:30 UTC
e07446ed5ff8b1c291a5c4ba2783bb8c0aa9741a
1 file changed
+31
-1
git-gui.sh
+31
-1
@@ -2495,7 +2495,7 @@ proc force_first_diff {after} {
2495
2496
proc toggle_or_diff {mode w args} {
2497
global file_states file_lists current_diff_path ui_index ui_workdir
2498
- global last_clicked selected_paths
2498
+ global last_clicked selected_paths file_lists_last_clicked
2499
2500
if {$mode eq "click"} {
2501
foreach {x y} $args break
@@ -2527,6 +2527,8 @@ proc toggle_or_diff {mode w args} {
2527
$ui_index tag remove in_sel 0.0 end
2528
$ui_workdir tag remove in_sel 0.0 end
2529
2530
+ set file_lists_last_clicked($w) $path
2531
+
2532
# Determine the state of the file
2533
if {[info exists file_states($path)]} {
2534
set state [lindex $file_states($path) 0]
@@ -2640,6 +2642,26 @@ proc show_less_context {} {
2642
}
2643
}
2644
2645
+proc focus_widget {widget} {
2646
+ global file_lists last_clicked selected_paths
2647
+ global file_lists_last_clicked
2648
+
2649
+ if {[llength $file_lists($widget)] > 0} {
2650
+ set path $file_lists_last_clicked($widget)
2651
+ set index [lsearch -sorted -exact $file_lists($widget) $path]
2652
+ if {$index < 0} {
2653
+ set index 0
2654
+ set path [lindex $file_lists($widget) $index]
2655
+ }
2656
+
2657
+ focus $widget
2658
+ set last_clicked [list $widget [expr $index + 1]]
2659
+ array unset selected_paths
2660
+ set selected_paths($path) 1
2661
+ show_diff $path $widget
2662
+ }
2663
+}
2664
+
2665
######################################################################
2666
##
2667
## ui construction
@@ -3852,6 +3874,14 @@ foreach i [list $ui_index $ui_workdir] {
3874
}
3875
unset i
3876
3877
+bind . <Alt-Key-1> {focus_widget $::ui_workdir}
3878
+bind . <Alt-Key-2> {focus_widget $::ui_index}
3879
+bind . <Alt-Key-3> {focus $::ui_diff}
3880
+bind . <Alt-Key-4> {focus $::ui_comm}
3881
+
3882
+set file_lists_last_clicked($ui_index) {}
3883
+set file_lists_last_clicked($ui_workdir) {}
3884
+
3885
set file_lists($ui_index) [list]
3886
set file_lists($ui_workdir) [list]
3887