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

Re: [PATCH 2/2] git-gui: select staged on ui_comm focus

From
Pratyush Yadav <me@yadavpratyush.com>
Date
Oct 16, 2019, 19:25 UTC
Message-ID
<20191016192546.znhulmgxqqsjxy2u@yadavpratyush.com>
In-Reply-To
<20191007171145.1259-2-birger.sp@gmail.com>
On 07/10/19 07:11PM, Birger Skogeng Pedersen wrote:
Show 25 quoted lines
> When the user focuses the Commit Message widget (to write a message), the
> diff view may be blank.
> 
> With this patch a staged file is automatically selected when the Commit
> Message widget is focused, if no other file is selected (i.e. diff view
> is blank).
> 
> Signed-off-by: Birger Skogeng Pedersen <birger.sp@gmail.com>
> ---
>  git-gui.sh | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/git-gui.sh b/git-gui.sh
> index b7f4d1e..70b846a 100755
> --- a/git-gui.sh
> +++ b/git-gui.sh
> @@ -2700,6 +2700,15 @@ proc toggle_commit_type {} {
>  	do_select_commit_type
>  }
>  
> +proc check_diff_selected {} {
> +	global current_diff_path file_lists
> +	# If no diff path selected, select a staged file
> +	if {$current_diff_path eq {}
> +		&& [llength $file_lists($::ui_index)] > 0} {
Nitpick: Please declare ui_index to be global. That way we can just use 
$ui_index instead of the more tedious $::ui_index.
Show 13 quoted lines
> +		select_path_in_widget $::ui_index
> +	}
> +}
> +
>  ######################################################################
>  ##
>  ## ui construction
> @@ -3437,6 +3446,8 @@ pack .vpane.lower.commarea.buffer.header -side top -fill x
>  pack .vpane.lower.commarea.buffer.frame -side left -fill y
>  pack .vpane.lower.commarea.buffer -side left -fill y
>  
> +bind $ui_comm <FocusIn> {check_diff_selected}
> +

This would mean the diff shows _only_ when you switch focus to the commit message buffer. If the buffer is already in focus, and you stage all files via Ctrl-I, the staged diff would not show.

IIRC you were having some trouble with this. A quick suggestion without looking too much into the problem is to try putting the logic inside `do_add_all` instead of inside the bind event handler.

Show 6 quoted lines
>  # -- Commit Message Buffer Context Menu
>  #
>  set ctxm .vpane.lower.commarea.buffer.ctxm
> -- 
> 2.23.0.windows.1
> 
-- 
Regards,
Pratyush Yadav
Previous: Birger Skogeng PedersenNext: Pratyush Yadav
Message 13 of 22 in “git-gui: automatically move focus to staged file before typing commit message?”
  1. Birger Skogeng PedersenSep 14, 2019
  2. Pratyush YadavSep 14, 2019
  3. Johannes SixtSep 14, 2019
  4. Pratyush YadavSep 14, 2019
  5. Birger Skogeng PedersenSep 15, 2019
  6. Pratyush YadavSep 16, 2019
  7. Birger Skogeng PedersenSep 26, 2019
  8. Pratyush YadavSep 26, 2019
  9. Birger Skogeng PedersenSep 26, 2019
  10. Birger Skogeng PedersenOct 7, 2019
  11. 1/2 git-gui: implement proc select_path_in_widgetBirger Skogeng Pedersen, Oct 7, 2019
  12. 2/2 git-gui: select staged on ui_comm focusBirger Skogeng Pedersen, Oct 7, 2019
  13. Pratyush YadavOct 16, 2019
  14. Pratyush YadavOct 13, 2019
  15. Birger Skogeng PedersenOct 15, 2019
  16. Pratyush YadavOct 16, 2019
  17. Birger Skogeng PedersenOct 17, 2019
  18. Johannes SixtOct 17, 2019
  19. Birger Skogeng PedersenOct 17, 2019
  20. Pratyush YadavOct 17, 2019
  21. Pratyush YadavOct 8, 2019
  22. Birger Skogeng PedersenOct 8, 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.