Skip to content

Commit a470834

Browse files
committed
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.
1 parent 014f8a2 commit a470834

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

pkg/gui/controllers/commit_description_controller.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package controllers
22

33
import (
4+
"github.com/jesseduffield/gocui"
5+
"github.com/jesseduffield/lazygit/pkg/gui/context"
46
"github.com/jesseduffield/lazygit/pkg/gui/types"
57
)
68

@@ -47,6 +49,16 @@ func (self *CommitDescriptionController) Context() types.Context {
4749
return self.c.Contexts().CommitDescription
4850
}
4951

52+
func (self *CommitDescriptionController) GetMouseKeybindings(opts types.KeybindingsOpts) []*gocui.ViewMouseBinding {
53+
return []*gocui.ViewMouseBinding{
54+
{
55+
ViewName: self.Context().GetViewName(),
56+
Key: gocui.MouseLeft,
57+
Handler: self.onClick,
58+
},
59+
}
60+
}
61+
5062
func (self *CommitDescriptionController) switchToCommitMessage() error {
5163
return self.c.ReplaceContext(self.c.Contexts().CommitMessage)
5264
}
@@ -63,3 +75,12 @@ func (self *CommitDescriptionController) openCommitMenu() error {
6375
authorSuggestion := self.c.Helpers().Suggestions.GetAuthorsSuggestionsFunc()
6476
return self.c.Helpers().Commits.OpenCommitMenu(authorSuggestion)
6577
}
78+
79+
func (self *CommitDescriptionController) onClick(opts gocui.ViewMouseBindingOpts) error {
80+
// Activate the description panel when the commit message panel is currently active
81+
if self.c.CurrentContext().GetKey() == context.COMMIT_MESSAGE_CONTEXT_KEY {
82+
return self.c.ReplaceContext(self.c.Contexts().CommitDescription)
83+
}
84+
85+
return nil
86+
}

pkg/gui/controllers/commit_message_controller.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package controllers
33
import (
44
"errors"
55

6+
"github.com/jesseduffield/gocui"
67
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
78
"github.com/jesseduffield/lazygit/pkg/gui/context"
89
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
@@ -58,6 +59,16 @@ func (self *CommitMessageController) GetKeybindings(opts types.KeybindingsOpts)
5859
return bindings
5960
}
6061

62+
func (self *CommitMessageController) GetMouseKeybindings(opts types.KeybindingsOpts) []*gocui.ViewMouseBinding {
63+
return []*gocui.ViewMouseBinding{
64+
{
65+
ViewName: self.Context().GetViewName(),
66+
Key: gocui.MouseLeft,
67+
Handler: self.onClick,
68+
},
69+
}
70+
}
71+
6172
func (self *CommitMessageController) GetOnFocusLost() func(types.OnFocusLostOpts) error {
6273
return func(types.OnFocusLostOpts) error {
6374
self.context().RenderCommitLength()
@@ -137,3 +148,12 @@ func (self *CommitMessageController) openCommitMenu() error {
137148
authorSuggestion := self.c.Helpers().Suggestions.GetAuthorsSuggestionsFunc()
138149
return self.c.Helpers().Commits.OpenCommitMenu(authorSuggestion)
139150
}
151+
152+
func (self *CommitMessageController) onClick(opts gocui.ViewMouseBindingOpts) error {
153+
// Activate the commit message panel when the commit description panel is currently active
154+
if self.c.CurrentContext().GetKey() == context.COMMIT_DESCRIPTION_CONTEXT_KEY {
155+
return self.c.ReplaceContext(self.c.Contexts().CommitMessage)
156+
}
157+
158+
return nil
159+
}

pkg/gui/keybindings.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,14 @@ func (gui *Gui) SetKeybinding(binding *types.Binding) error {
424424
func (gui *Gui) SetMouseKeybinding(binding *gocui.ViewMouseBinding) error {
425425
baseHandler := binding.Handler
426426
newHandler := func(opts gocui.ViewMouseBindingOpts) error {
427-
// we ignore click events on views that aren't popup panels, when a popup panel is focused
428-
if gui.helpers.Confirmation.IsPopupPanelFocused() && gui.currentViewName() != binding.ViewName {
427+
// we ignore click events on views that aren't popup panels, when a popup panel is focused.
428+
// Unless both the current view and the clicked-on view are either commit message or commit
429+
// description, because we want to allow switching between those two views by clicking.
430+
isCommitMessageView := func(viewName string) bool {
431+
return viewName == "commitMessage" || viewName == "commitDescription"
432+
}
433+
if gui.helpers.Confirmation.IsPopupPanelFocused() && gui.currentViewName() != binding.ViewName &&
434+
(!isCommitMessageView(gui.currentViewName()) || !isCommitMessageView(binding.ViewName)) {
429435
return nil
430436
}
431437

0 commit comments

Comments
 (0)