mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-30 03:23:08 +03:00
Allow switching between commit message and description by clicking
It is annoying to have to tab to the description first before you can set the cursor there by clicking.
This commit is contained in:
@ -1,6 +1,8 @@
|
|||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/jesseduffield/gocui"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -47,6 +49,16 @@ func (self *CommitDescriptionController) Context() types.Context {
|
|||||||
return self.c.Contexts().CommitDescription
|
return self.c.Contexts().CommitDescription
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *CommitDescriptionController) GetMouseKeybindings(opts types.KeybindingsOpts) []*gocui.ViewMouseBinding {
|
||||||
|
return []*gocui.ViewMouseBinding{
|
||||||
|
{
|
||||||
|
ViewName: self.Context().GetViewName(),
|
||||||
|
Key: gocui.MouseLeft,
|
||||||
|
Handler: self.onClick,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (self *CommitDescriptionController) switchToCommitMessage() error {
|
func (self *CommitDescriptionController) switchToCommitMessage() error {
|
||||||
return self.c.Context().Replace(self.c.Contexts().CommitMessage)
|
return self.c.Context().Replace(self.c.Contexts().CommitMessage)
|
||||||
}
|
}
|
||||||
@ -63,3 +75,12 @@ func (self *CommitDescriptionController) openCommitMenu() error {
|
|||||||
authorSuggestion := self.c.Helpers().Suggestions.GetAuthorsSuggestionsFunc()
|
authorSuggestion := self.c.Helpers().Suggestions.GetAuthorsSuggestionsFunc()
|
||||||
return self.c.Helpers().Commits.OpenCommitMenu(authorSuggestion)
|
return self.c.Helpers().Commits.OpenCommitMenu(authorSuggestion)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
return self.c.Context().Replace(self.c.Contexts().CommitDescription)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -3,6 +3,7 @@ package controllers
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
|
"github.com/jesseduffield/gocui"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
|
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
|
||||||
@ -58,6 +59,16 @@ func (self *CommitMessageController) GetKeybindings(opts types.KeybindingsOpts)
|
|||||||
return bindings
|
return bindings
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *CommitMessageController) GetMouseKeybindings(opts types.KeybindingsOpts) []*gocui.ViewMouseBinding {
|
||||||
|
return []*gocui.ViewMouseBinding{
|
||||||
|
{
|
||||||
|
ViewName: self.Context().GetViewName(),
|
||||||
|
Key: gocui.MouseLeft,
|
||||||
|
Handler: self.onClick,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (self *CommitMessageController) GetOnFocusLost() func(types.OnFocusLostOpts) error {
|
func (self *CommitMessageController) GetOnFocusLost() func(types.OnFocusLostOpts) error {
|
||||||
return func(types.OnFocusLostOpts) error {
|
return func(types.OnFocusLostOpts) error {
|
||||||
self.context().RenderCommitLength()
|
self.context().RenderCommitLength()
|
||||||
@ -137,3 +148,12 @@ func (self *CommitMessageController) openCommitMenu() error {
|
|||||||
authorSuggestion := self.c.Helpers().Suggestions.GetAuthorsSuggestionsFunc()
|
authorSuggestion := self.c.Helpers().Suggestions.GetAuthorsSuggestionsFunc()
|
||||||
return self.c.Helpers().Commits.OpenCommitMenu(authorSuggestion)
|
return self.c.Helpers().Commits.OpenCommitMenu(authorSuggestion)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
return self.c.Context().Replace(self.c.Contexts().CommitMessage)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -424,8 +424,14 @@ func (gui *Gui) SetKeybinding(binding *types.Binding) error {
|
|||||||
func (gui *Gui) SetMouseKeybinding(binding *gocui.ViewMouseBinding) error {
|
func (gui *Gui) SetMouseKeybinding(binding *gocui.ViewMouseBinding) error {
|
||||||
baseHandler := binding.Handler
|
baseHandler := binding.Handler
|
||||||
newHandler := func(opts gocui.ViewMouseBindingOpts) error {
|
newHandler := func(opts gocui.ViewMouseBindingOpts) error {
|
||||||
// we ignore click events on views that aren't popup panels, when a popup panel is focused
|
// we ignore click events on views that aren't popup panels, when a popup panel is focused.
|
||||||
if gui.helpers.Confirmation.IsPopupPanelFocused() && gui.currentViewName() != binding.ViewName {
|
// Unless both the current view and the clicked-on view are either commit message or commit
|
||||||
|
// description, because we want to allow switching between those two views by clicking.
|
||||||
|
isCommitMessageView := func(viewName string) bool {
|
||||||
|
return viewName == "commitMessage" || viewName == "commitDescription"
|
||||||
|
}
|
||||||
|
if gui.helpers.Confirmation.IsPopupPanelFocused() && gui.currentViewName() != binding.ViewName &&
|
||||||
|
(!isCommitMessageView(gui.currentViewName()) || !isCommitMessageView(binding.ViewName)) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user