From f6c20f2745b0e93bc3a991533368c363d8bb05bf Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 10 Jul 2025 17:46:43 +0200 Subject: [PATCH] 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. --- .../controllers/commit_description_controller.go | 14 +++++--------- pkg/gui/controllers/commit_message_controller.go | 13 +++++-------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/pkg/gui/controllers/commit_description_controller.go b/pkg/gui/controllers/commit_description_controller.go index 1247de076..24653c767 100644 --- a/pkg/gui/controllers/commit_description_controller.go +++ b/pkg/gui/controllers/commit_description_controller.go @@ -2,7 +2,6 @@ package controllers import ( "github.com/jesseduffield/gocui" - "github.com/jesseduffield/lazygit/pkg/gui/context" "github.com/jesseduffield/lazygit/pkg/gui/keybindings" "github.com/jesseduffield/lazygit/pkg/gui/types" "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 { return []*gocui.ViewMouseBinding{ { - ViewName: self.Context().GetViewName(), - Key: gocui.MouseLeft, - Handler: self.onClick, + ViewName: self.Context().GetViewName(), + FocusedView: self.c.Contexts().CommitMessage.GetViewName(), + Key: gocui.MouseLeft, + Handler: self.onClick, }, } } @@ -137,10 +137,6 @@ func (self *CommitDescriptionController) openCommitMenu() error { } func (self *CommitDescriptionController) onClick(opts gocui.ViewMouseBindingOpts) error { - // Activate the description panel when the commit message panel is currently active - if self.c.Context().Current().GetKey() == context.COMMIT_MESSAGE_CONTEXT_KEY { - self.c.Context().Replace(self.c.Contexts().CommitDescription) - } - + self.c.Context().Replace(self.c.Contexts().CommitDescription) return nil } diff --git a/pkg/gui/controllers/commit_message_controller.go b/pkg/gui/controllers/commit_message_controller.go index 6f96cdd21..e9ff1bc67 100644 --- a/pkg/gui/controllers/commit_message_controller.go +++ b/pkg/gui/controllers/commit_message_controller.go @@ -62,9 +62,10 @@ func (self *CommitMessageController) GetKeybindings(opts types.KeybindingsOpts) func (self *CommitMessageController) GetMouseKeybindings(opts types.KeybindingsOpts) []*gocui.ViewMouseBinding { return []*gocui.ViewMouseBinding{ { - ViewName: self.Context().GetViewName(), - Key: gocui.MouseLeft, - Handler: self.onClick, + ViewName: self.Context().GetViewName(), + FocusedView: self.c.Contexts().CommitDescription.GetViewName(), + Key: gocui.MouseLeft, + Handler: self.onClick, }, } } @@ -194,10 +195,6 @@ func (self *CommitMessageController) openCommitMenu() error { } func (self *CommitMessageController) onClick(opts gocui.ViewMouseBindingOpts) error { - // Activate the commit message panel when the commit description panel is currently active - if self.c.Context().Current().GetKey() == context.COMMIT_DESCRIPTION_CONTEXT_KEY { - self.c.Context().Replace(self.c.Contexts().CommitMessage) - } - + self.c.Context().Replace(self.c.Contexts().CommitMessage) return nil }