Skip to content

Commit e07446e

Browse files
birgerspprati0100
authored andcommitted
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 <[email protected]> Signed-off-by: Pratyush Yadav <[email protected]>
1 parent 5ab7227 commit e07446e

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

git-gui.sh

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2495,7 +2495,7 @@ proc force_first_diff {after} {
24952495
24962496
proc toggle_or_diff {mode w args} {
24972497
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
24992499
25002500
if {$mode eq "click"} {
25012501
foreach {x y} $args break
@@ -2527,6 +2527,8 @@ proc toggle_or_diff {mode w args} {
25272527
$ui_index tag remove in_sel 0.0 end
25282528
$ui_workdir tag remove in_sel 0.0 end
25292529
2530+
set file_lists_last_clicked($w) $path
2531+
25302532
# Determine the state of the file
25312533
if {[info exists file_states($path)]} {
25322534
set state [lindex $file_states($path) 0]
@@ -2640,6 +2642,26 @@ proc show_less_context {} {
26402642
}
26412643
}
26422644
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+
26432665
######################################################################
26442666
##
26452667
## ui construction
@@ -3852,6 +3874,14 @@ foreach i [list $ui_index $ui_workdir] {
38523874
}
38533875
unset i
38543876
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+
38553885
set file_lists($ui_index) [list]
38563886
set file_lists($ui_workdir) [list]
38573887

0 commit comments

Comments
 (0)