mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-05-02 21:24:45 +02:00
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
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user