Skip to content

Commit 088ad75

Browse files
committed
Allow keyboard control to work in the staging widgets.
Keyboard focus was restricted to the commit message widget and users were forced to use the mouse to select files in the workdir widget and only then could use a key combination to stage the file. It is now possible to use key navigation (Ctrl-Tab, arrow keys and Ctrl-T or Ctrl-U) to stage and unstage files. Suggested by @koppor in git-for-window/git issue #859 Signed-off-by: Pat Thoyts <[email protected]>
1 parent 82b2cab commit 088ad75

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

git-gui.sh

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2505,20 +2505,36 @@ proc force_first_diff {after} {
25052505
}
25062506
}
25072507
2508-
proc toggle_or_diff {w x y} {
2508+
proc toggle_or_diff {mode w args} {
25092509
global file_states file_lists current_diff_path ui_index ui_workdir
25102510
global last_clicked selected_paths
25112511
2512-
set pos [split [$w index @$x,$y] .]
2513-
set lno [lindex $pos 0]
2514-
set col [lindex $pos 1]
2512+
if {$mode eq "click"} {
2513+
foreach {x y} $args break
2514+
set pos [split [$w index @$x,$y] .]
2515+
foreach {lno col} $pos break
2516+
} else {
2517+
if {$last_clicked ne {}} {
2518+
set lno [lindex $last_clicked 1]
2519+
} else {
2520+
set lno [expr {int([lindex [$w tag ranges in_diff] 0])}]
2521+
}
2522+
if {$mode eq "toggle"} {
2523+
set col 0; set y 2
2524+
} else {
2525+
incr lno [expr {$mode eq "up" ? -1 : 1}]
2526+
set col 1
2527+
}
2528+
}
2529+
25152530
set path [lindex $file_lists($w) [expr {$lno - 1}]]
25162531
if {$path eq {}} {
25172532
set last_clicked {}
25182533
return
25192534
}
25202535
25212536
set last_clicked [list $w $lno]
2537+
focus $w
25222538
array unset selected_paths
25232539
$ui_index tag remove in_sel 0.0 end
25242540
$ui_workdir tag remove in_sel 0.0 end
@@ -2598,7 +2614,7 @@ proc add_range_to_selection {w x y} {
25982614
global file_lists last_clicked selected_paths
25992615
26002616
if {[lindex $last_clicked 0] ne $w} {
2601-
toggle_or_diff $w $x $y
2617+
toggle_or_diff click $w $x $y
26022618
return
26032619
}
26042620
@@ -3188,6 +3204,7 @@ text $ui_index -background white -foreground black \
31883204
-borderwidth 0 \
31893205
-width 20 -height 10 \
31903206
-wrap none \
3207+
-takefocus 1 -highlightthickness 1\
31913208
-cursor $cursor_ptr \
31923209
-xscrollcommand {.vpane.files.index.sx set} \
31933210
-yscrollcommand {.vpane.files.index.sy set} \
@@ -3208,6 +3225,7 @@ text $ui_workdir -background white -foreground black \
32083225
-borderwidth 0 \
32093226
-width 20 -height 10 \
32103227
-wrap none \
3228+
-takefocus 1 -highlightthickness 1\
32113229
-cursor $cursor_ptr \
32123230
-xscrollcommand {.vpane.files.workdir.sx set} \
32133231
-yscrollcommand {.vpane.files.workdir.sy set} \
@@ -3815,10 +3833,10 @@ bind . <$M1B-Key-r> ui_do_rescan
38153833
bind . <$M1B-Key-R> ui_do_rescan
38163834
bind . <$M1B-Key-s> do_signoff
38173835
bind . <$M1B-Key-S> do_signoff
3818-
bind . <$M1B-Key-t> do_add_selection
3819-
bind . <$M1B-Key-T> do_add_selection
3820-
bind . <$M1B-Key-u> do_unstage_selection
3821-
bind . <$M1B-Key-U> do_unstage_selection
3836+
bind . <$M1B-Key-t> { toggle_or_diff toggle %W }
3837+
bind . <$M1B-Key-T> { toggle_or_diff toggle %W }
3838+
bind . <$M1B-Key-u> { toggle_or_diff toggle %W }
3839+
bind . <$M1B-Key-U> { toggle_or_diff toggle %W }
38223840
bind . <$M1B-Key-j> do_revert_selection
38233841
bind . <$M1B-Key-J> do_revert_selection
38243842
bind . <$M1B-Key-i> do_add_all
@@ -3830,9 +3848,11 @@ bind . <$M1B-Key-plus> {show_more_context;break}
38303848
bind . <$M1B-Key-KP_Add> {show_more_context;break}
38313849
bind . <$M1B-Key-Return> do_commit
38323850
foreach i [list $ui_index $ui_workdir] {
3833-
bind $i <Button-1> "toggle_or_diff $i %x %y; break"
3834-
bind $i <$M1B-Button-1> "add_one_to_selection $i %x %y; break"
3835-
bind $i <Shift-Button-1> "add_range_to_selection $i %x %y; break"
3851+
bind $i <Button-1> { toggle_or_diff click %W %x %y; break }
3852+
bind $i <$M1B-Button-1> { add_one_to_selection %W %x %y; break }
3853+
bind $i <Shift-Button-1> { add_range_to_selection %W %x %y; break }
3854+
bind $i <Key-Up> { toggle_or_diff up %W; break }
3855+
bind $i <Key-Down> { toggle_or_diff down %W; break }
38363856
}
38373857
unset i
38383858

0 commit comments

Comments
 (0)