Skip to content

Commit 8a8dc91

Browse files
committed
Use new ShouldHandleMouseEvent hook to prevent clicks in views behind panels
This fixes two problems: - if the previously focused view (behind the panel) was a list view, it would look like the click would select a different row, because gocui would still set the view's cursor position, which is used to draw the highlighted row - it was still possible to click on tab headers, and this would dismiss the panel
1 parent 87691a1 commit 8a8dc91

2 files changed

Lines changed: 19 additions & 22 deletions

File tree

pkg/gui/gui.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,25 @@ func (gui *Gui) Run(startArgs appTypes.StartArgs) error {
842842

843843
g.ErrorHandler = gui.PopupHandler.ErrorHandler
844844

845+
gui.g.ShouldHandleMouseEvent = func(view *gocui.View, key gocui.Key) bool {
846+
if gui.helpers.Confirmation.IsPopupPanelFocused() && gui.currentViewName() != view.Name() &&
847+
!gocui.IsMouseScrollKey(key) {
848+
// we ignore click events on views that aren't popup panels, when a popup panel is focused.
849+
// Unless both the current view and the clicked-on view are either commit message or commit
850+
// description, or a prompt and the suggestions view, because we want to allow switching
851+
// between those two views by clicking.
852+
isCommitMessageOrSuggestionsView := func(viewName string) bool {
853+
return viewName == "commitMessage" || viewName == "commitDescription" ||
854+
viewName == "prompt" || viewName == "suggestions"
855+
}
856+
if !isCommitMessageOrSuggestionsView(gui.currentViewName()) || !isCommitMessageOrSuggestionsView(view.Name()) {
857+
return false
858+
}
859+
}
860+
861+
return true
862+
}
863+
845864
// if the deadlock package wants to report a deadlock, we first need to
846865
// close the gui so that we can actually read what it prints.
847866
deadlock.Opts.LogBuf = utils.NewOnceWriter(os.Stderr, func() {

pkg/gui/keybindings.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -499,29 +499,7 @@ func (gui *Gui) SetKeybinding(binding *types.Binding) error {
499499
return gui.g.SetKeybinding(binding.ViewName, binding.Key, binding.Modifier, gui.wrappedHandler(handler))
500500
}
501501

502-
// warning: mutates the binding
503502
func (gui *Gui) SetMouseKeybinding(binding *gocui.ViewMouseBinding) error {
504-
baseHandler := binding.Handler
505-
newHandler := func(opts gocui.ViewMouseBindingOpts) error {
506-
if gui.helpers.Confirmation.IsPopupPanelFocused() && gui.currentViewName() != binding.ViewName &&
507-
!gocui.IsMouseScrollKey(opts.Key) {
508-
// we ignore click events on views that aren't popup panels, when a popup panel is focused.
509-
// Unless both the current view and the clicked-on view are either commit message or commit
510-
// description, or a prompt and the suggestions view, because we want to allow switching
511-
// between those two views by clicking.
512-
isCommitMessageOrSuggestionsView := func(viewName string) bool {
513-
return viewName == "commitMessage" || viewName == "commitDescription" ||
514-
viewName == "prompt" || viewName == "suggestions"
515-
}
516-
if !isCommitMessageOrSuggestionsView(gui.currentViewName()) || !isCommitMessageOrSuggestionsView(binding.ViewName) {
517-
return nil
518-
}
519-
}
520-
521-
return baseHandler(opts)
522-
}
523-
binding.Handler = newHandler
524-
525503
return gui.g.SetViewClickBinding(binding)
526504
}
527505

0 commit comments

Comments
 (0)