Skip to content

Commit 5a2bb62

Browse files
committed
Merge branch 'bp/widget-focus-hotkeys'
git-gui learned to switch focus between widgets "unstaged commits", "staged commits", "diff", and "commit message" using the keyboard shortcuts Alt+1, Alt+2, Alt+3, and Alt+4 respectively. * bp/widget-focus-hotkeys: git-gui: add hotkeys to set widget focus
2 parents 5ab7227 + e07446e commit 5a2bb62

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)