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