diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index f3b752cee..34d388391 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -842,6 +842,25 @@ func (gui *Gui) Run(startArgs appTypes.StartArgs) error { g.ErrorHandler = gui.PopupHandler.ErrorHandler + gui.g.ShouldHandleMouseEvent = func(view *gocui.View, key gocui.Key) bool { + if gui.helpers.Confirmation.IsPopupPanelFocused() && gui.currentViewName() != view.Name() && + !gocui.IsMouseScrollKey(key) { + // 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, or a prompt and the suggestions view, because we want to allow switching + // between those two views by clicking. + isCommitMessageOrSuggestionsView := func(viewName string) bool { + return viewName == "commitMessage" || viewName == "commitDescription" || + viewName == "prompt" || viewName == "suggestions" + } + if !isCommitMessageOrSuggestionsView(gui.currentViewName()) || !isCommitMessageOrSuggestionsView(view.Name()) { + return false + } + } + + return true + } + // if the deadlock package wants to report a deadlock, we first need to // close the gui so that we can actually read what it prints. deadlock.Opts.LogBuf = utils.NewOnceWriter(os.Stderr, func() { diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 084a25159..9f92fbae8 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -499,29 +499,7 @@ func (gui *Gui) SetKeybinding(binding *types.Binding) error { return gui.g.SetKeybinding(binding.ViewName, binding.Key, binding.Modifier, gui.wrappedHandler(handler)) } -// warning: mutates the binding func (gui *Gui) SetMouseKeybinding(binding *gocui.ViewMouseBinding) error { - baseHandler := binding.Handler - newHandler := func(opts gocui.ViewMouseBindingOpts) error { - if gui.helpers.Confirmation.IsPopupPanelFocused() && gui.currentViewName() != binding.ViewName && - !gocui.IsMouseScrollKey(opts.Key) { - // 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, or a prompt and the suggestions view, because we want to allow switching - // between those two views by clicking. - isCommitMessageOrSuggestionsView := func(viewName string) bool { - return viewName == "commitMessage" || viewName == "commitDescription" || - viewName == "prompt" || viewName == "suggestions" - } - if !isCommitMessageOrSuggestionsView(gui.currentViewName()) || !isCommitMessageOrSuggestionsView(binding.ViewName) { - return nil - } - } - - return baseHandler(opts) - } - binding.Handler = newHandler - return gui.g.SetViewClickBinding(binding) }