1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-08-06 22:33:07 +02:00

Cleanup: use FocusedView property for mouse bindings

This way the click is only handled if a given view has the focus, and we don't
have to check this manually in the handler.
This commit is contained in:
Stefan Haller
2025-07-10 17:46:43 +02:00
parent 2e5cf46716
commit f6c20f2745
2 changed files with 10 additions and 17 deletions

View File

@ -2,7 +2,6 @@ package controllers
import ( import (
"github.com/jesseduffield/gocui" "github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/keybindings" "github.com/jesseduffield/lazygit/pkg/gui/keybindings"
"github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/utils" "github.com/jesseduffield/lazygit/pkg/utils"
@ -58,9 +57,10 @@ func (self *CommitDescriptionController) Context() types.Context {
func (self *CommitDescriptionController) GetMouseKeybindings(opts types.KeybindingsOpts) []*gocui.ViewMouseBinding { func (self *CommitDescriptionController) GetMouseKeybindings(opts types.KeybindingsOpts) []*gocui.ViewMouseBinding {
return []*gocui.ViewMouseBinding{ return []*gocui.ViewMouseBinding{
{ {
ViewName: self.Context().GetViewName(), ViewName: self.Context().GetViewName(),
Key: gocui.MouseLeft, FocusedView: self.c.Contexts().CommitMessage.GetViewName(),
Handler: self.onClick, Key: gocui.MouseLeft,
Handler: self.onClick,
}, },
} }
} }
@ -137,10 +137,6 @@ func (self *CommitDescriptionController) openCommitMenu() error {
} }
func (self *CommitDescriptionController) onClick(opts gocui.ViewMouseBindingOpts) error { func (self *CommitDescriptionController) onClick(opts gocui.ViewMouseBindingOpts) error {
// Activate the description panel when the commit message panel is currently active self.c.Context().Replace(self.c.Contexts().CommitDescription)
if self.c.Context().Current().GetKey() == context.COMMIT_MESSAGE_CONTEXT_KEY {
self.c.Context().Replace(self.c.Contexts().CommitDescription)
}
return nil return nil
} }

View File

@ -62,9 +62,10 @@ func (self *CommitMessageController) GetKeybindings(opts types.KeybindingsOpts)
func (self *CommitMessageController) GetMouseKeybindings(opts types.KeybindingsOpts) []*gocui.ViewMouseBinding { func (self *CommitMessageController) GetMouseKeybindings(opts types.KeybindingsOpts) []*gocui.ViewMouseBinding {
return []*gocui.ViewMouseBinding{ return []*gocui.ViewMouseBinding{
{ {
ViewName: self.Context().GetViewName(), ViewName: self.Context().GetViewName(),
Key: gocui.MouseLeft, FocusedView: self.c.Contexts().CommitDescription.GetViewName(),
Handler: self.onClick, Key: gocui.MouseLeft,
Handler: self.onClick,
}, },
} }
} }
@ -194,10 +195,6 @@ func (self *CommitMessageController) openCommitMenu() error {
} }
func (self *CommitMessageController) onClick(opts gocui.ViewMouseBindingOpts) error { func (self *CommitMessageController) onClick(opts gocui.ViewMouseBindingOpts) error {
// Activate the commit message panel when the commit description panel is currently active self.c.Context().Replace(self.c.Contexts().CommitMessage)
if self.c.Context().Current().GetKey() == context.COMMIT_DESCRIPTION_CONTEXT_KEY {
self.c.Context().Replace(self.c.Contexts().CommitMessage)
}
return nil return nil
} }