git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v5] git-gui: Add hotkeys to set widget focus

From
Pratyush Yadav <me@yadavpratyush.com>
Date
Sep 10, 2019, 19:12 UTC
Message-ID
<20190910191217.qgb23x5tvaajppfh@yadavpratyush.com>
In-Reply-To
<20190904143055.11400-1-birger.sp@gmail.com>
+Cc j6t

This patch LGTM, but I'm not sure how to resolve the keybindings problem. Junio suggested we have configurable keybindings, and I agree with him, but until we do, something has to be agreed upon. And we also need to come up with a reasonable default.

So, I don't have any preferences for either using Alt+3 for the commit message buffer, or Alt+4. Unless someone has objections, I'll go with Alt+3 for the commit message buffer, and Alt+4 for the diff.

Thanks for the patch Birger. I'll change the keybindings locally before pushing out, no need to send a re-roll for something so trivial.

On 04/09/19 04:30PM, Birger Skogeng Pedersen wrote:
Show 86 quoted lines
> 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>
> ---
>  git-gui.sh | 32 +++++++++++++++++++++++++++++++-
>  1 file changed, 31 insertions(+), 1 deletion(-)
> 
> 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]
>  
> -- 
> 2.21.0.windows.1
> 
-- 
Regards,
Pratyush Yadav
Previous: Johannes SixtNext: Birger Skogeng Pedersen
Message 36 of 46 in “git-gui, feature request: add hotkeys to focus different widgets”
  1. Birger Skogeng PedersenFeb 20, 2018
  2. git-gui: Add hotkeys to change focus between ui widgetsBirger Skogeng Pedersen, Feb 23, 2018
  3. Birger Skogeng PedersenFeb 23, 2018
  4. git-gui: Add hotkeys to change focus between ui widgetsBirger Skogeng Pedersen, Feb 28, 2018
  5. Johannes SchindelinMar 5, 2018
  6. Birger Skogeng PedersenMar 6, 2018
  7. Junio C HamanoMar 6, 2018
  8. git-gui: Add hotkeys to set widget focusBirger Skogeng Pedersen, Aug 31, 2019
  9. Birger Skogeng PedersenAug 31, 2019
  10. Pratyush YadavSep 1, 2019
  11. Junio C HamanoSep 1, 2019
  12. Birger Skogeng PedersenSep 1, 2019
  13. Bert WesargSep 1, 2019
  14. [PATCH] git-gui: Add hotkeys to set widget focusBirger Skogeng Pedersen, Sep 1, 2019
  15. Pratyush YadavSep 2, 2019
  16. Birger Skogeng PedersenSep 2, 2019
  17. Pratyush YadavSep 2, 2019
  18. Birger Skogeng PedersenSep 2, 2019
  19. Bert WesargSep 2, 2019
  20. Birger Skogeng PedersenSep 3, 2019
  21. Pratyush YadavSep 3, 2019
  22. git-gui: use path name instead of list index to track last clicked filePratyush Yadav, Sep 3, 2019
  23. git-gui: Add hotkeys to set widget focusBirger Skogeng Pedersen, Sep 3, 2019
  24. Birger Skogeng PedersenSep 3, 2019
  25. Birger Skogeng PedersenSep 3, 2019
  26. Pratyush YadavSep 3, 2019
  27. git-gui: Add hotkeys to set widget focusBirger Skogeng Pedersen, Sep 4, 2019
  28. Johannes SixtSep 4, 2019
  29. Birger Skogeng PedersenSep 4, 2019
  30. Johannes SixtSep 4, 2019
  31. Pratyush YadavSep 4, 2019
  32. Junio C HamanoSep 4, 2019
  33. Pratyush YadavSep 5, 2019
  34. Bert WesargSep 4, 2019
  35. Johannes SixtSep 4, 2019
  36. Pratyush YadavSep 10, 2019
  37. Birger Skogeng PedersenSep 11, 2019
  38. Pratyush YadavSep 11, 2019
  39. Johannes SixtSep 11, 2019
  40. Bert WesargSep 3, 2019
  41. Philip OakleySep 1, 2019
  42. Pratyush YadavSep 2, 2019
  43. Philip OakleySep 2, 2019
  44. Pratyush YadavSep 3, 2019
  45. Bert WesargSep 1, 2019
  46. Birger Skogeng PedersenSep 1, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.