From 2e5cf46716417e8a723dd9beb795ebc21cd39e6d Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 10 Jul 2025 15:06:30 +0200 Subject: [PATCH] Make conditions easier to understand This doesn't change behavior, just makes the code a little bit easier to understand: the outermost condition is "do we show a popup and is the mouse event for some other view than the focused one". Only if that's true do we need to define the isCommitMessageView function, and check whether both views belong to the commit message editor. --- pkg/gui/keybindings.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 4b41ebe1d..029cb4598 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -504,15 +504,16 @@ func (gui *Gui) SetKeybinding(binding *types.Binding) error { func (gui *Gui) SetMouseKeybinding(binding *gocui.ViewMouseBinding) error { baseHandler := binding.Handler newHandler := func(opts gocui.ViewMouseBindingOpts) error { - // we ignore click events on views that aren't popup panels, when a popup panel is focused. - // Unless both the current view and the clicked-on view are either commit message or commit - // description, because we want to allow switching between those two views by clicking. - isCommitMessageView := func(viewName string) bool { - return viewName == "commitMessage" || viewName == "commitDescription" - } - if gui.helpers.Confirmation.IsPopupPanelFocused() && gui.currentViewName() != binding.ViewName && - (!isCommitMessageView(gui.currentViewName()) || !isCommitMessageView(binding.ViewName)) { - return nil + if gui.helpers.Confirmation.IsPopupPanelFocused() && gui.currentViewName() != binding.ViewName { + // we ignore click events on views that aren't popup panels, when a popup panel is focused. + // Unless both the current view and the clicked-on view are either commit message or commit + // description, because we want to allow switching between those two views by clicking. + isCommitMessageView := func(viewName string) bool { + return viewName == "commitMessage" || viewName == "commitDescription" + } + if !isCommitMessageView(gui.currentViewName()) || !isCommitMessageView(binding.ViewName) { + return nil + } } return baseHandler(opts)