summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBirger Skogeng Pedersen <birger.sp@gmail.com>2019-09-04 14:30:55 (GMT)
committerPratyush Yadav <me@yadavpratyush.com>2019-09-10 19:16:21 (GMT)
commite07446ed5ff8b1c291a5c4ba2783bb8c0aa9741a (patch)
treecf89a9ff46de8051c57b2650e5aeff8e0addb13f
parent5ab72271e16ac23c269f5019a74a7b1d65170e47 (diff)
downloadgit-e07446ed5ff8b1c291a5c4ba2783bb8c0aa9741a.zip
git-e07446ed5ff8b1c291a5c4ba2783bb8c0aa9741a.tar.gz
git-e07446ed5ff8b1c291a5c4ba2783bb8c0aa9741a.tar.bz2
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>
-rwxr-xr-xgit-gui.sh32
1 files changed, 31 insertions, 1 deletions
diff --git a/git-gui.sh b/git-gui.sh
index 5bc21b8..5dae8da 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -2495,7 +2495,7 @@ proc force_first_diff {after} {
proc toggle_or_diff {mode w args} {
global file_states file_lists current_diff_path ui_index ui_workdir
- global last_clicked selected_paths
+ global last_clicked selected_paths file_lists_last_clicked
if {$mode eq "click"} {
foreach {x y} $args break
@@ -2527,6 +2527,8 @@ proc toggle_or_diff {mode w args} {
$ui_index tag remove in_sel 0.0 end
$ui_workdir tag remove in_sel 0.0 end
+ set file_lists_last_clicked($w) $path
+
# Determine the state of the file
if {[info exists file_states($path)]} {
set state [lindex $file_states($path) 0]
@@ -2640,6 +2642,26 @@ proc show_less_context {} {
}
}
+proc focus_widget {widget} {
+ global file_lists last_clicked selected_paths
+ global file_lists_last_clicked
+
+ if {[llength $file_lists($widget)] > 0} {
+ set path $file_lists_last_clicked($widget)
+ set index [lsearch -sorted -exact $file_lists($widget) $path]
+ if {$index < 0} {
+ set index 0
+ set path [lindex $file_lists($widget) $index]
+ }
+
+ focus $widget
+ set last_clicked [list $widget [expr $index + 1]]
+ array unset selected_paths
+ set selected_paths($path) 1
+ show_diff $path $widget
+ }
+}
+
######################################################################
##
## ui construction
@@ -3852,6 +3874,14 @@ foreach i [list $ui_index $ui_workdir] {
}
unset i
+bind . <Alt-Key-1> {focus_widget $::ui_workdir}
+bind . <Alt-Key-2> {focus_widget $::ui_index}
+bind . <Alt-Key-3> {focus $::ui_diff}
+bind . <Alt-Key-4> {focus $::ui_comm}
+
+set file_lists_last_clicked($ui_index) {}
+set file_lists_last_clicked($ui_workdir) {}
+
set file_lists($ui_index) [list]
set file_lists($ui_workdir) [list]