Skip to content

Commit 3ff4552

Browse files
committed
Allow switching between confirmation and suggestions by clicking
This is very similar to what we are doing to allow switching between commit subject and description in the commit message editor.
1 parent 21dd901 commit 3ff4552

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

pkg/gui/controllers/confirmation_controller.go

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

6+
"github.com/jesseduffield/gocui"
67
"github.com/jesseduffield/lazygit/pkg/gui/context"
78
"github.com/jesseduffield/lazygit/pkg/gui/types"
89
)
@@ -51,6 +52,22 @@ func (self *ConfirmationController) GetKeybindings(opts types.KeybindingsOpts) [
5152
return bindings
5253
}
5354

55+
func (self *ConfirmationController) GetMouseKeybindings(opts types.KeybindingsOpts) []*gocui.ViewMouseBinding {
56+
return []*gocui.ViewMouseBinding{
57+
{
58+
ViewName: self.c.Contexts().Suggestions.GetViewName(),
59+
FocusedView: self.c.Contexts().Confirmation.GetViewName(),
60+
Key: gocui.MouseLeft,
61+
Handler: func(gocui.ViewMouseBindingOpts) error {
62+
self.switchToSuggestions()
63+
// Let it fall through to the ListController's click handler so that
64+
// the clicked line gets selected:
65+
return gocui.ErrKeybindingNotHandled
66+
},
67+
},
68+
}
69+
}
70+
5471
func (self *ConfirmationController) GetOnFocusLost() func(types.OnFocusLostOpts) {
5572
return func(types.OnFocusLostOpts) {
5673
self.c.Helpers().Confirmation.DeactivateConfirmationPrompt()

pkg/gui/controllers/suggestions_controller.go

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

33
import (
4+
"github.com/jesseduffield/gocui"
45
"github.com/jesseduffield/lazygit/pkg/gui/context"
56
"github.com/jesseduffield/lazygit/pkg/gui/types"
67
)
@@ -69,6 +70,19 @@ func (self *SuggestionsController) GetKeybindings(opts types.KeybindingsOpts) []
6970
return bindings
7071
}
7172

73+
func (self *SuggestionsController) GetMouseKeybindings(opts types.KeybindingsOpts) []*gocui.ViewMouseBinding {
74+
return []*gocui.ViewMouseBinding{
75+
{
76+
ViewName: self.c.Contexts().Confirmation.GetViewName(),
77+
FocusedView: self.c.Contexts().Suggestions.GetViewName(),
78+
Key: gocui.MouseLeft,
79+
Handler: func(gocui.ViewMouseBindingOpts) error {
80+
return self.switchToConfirmation()
81+
},
82+
},
83+
}
84+
}
85+
7286
func (self *SuggestionsController) switchToConfirmation() error {
7387
self.c.Views().Suggestions.Subtitle = ""
7488
self.c.Views().Suggestions.Highlight = false

pkg/gui/keybindings.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -508,11 +508,13 @@ func (gui *Gui) SetMouseKeybinding(binding *gocui.ViewMouseBinding) error {
508508
!gocui.IsMouseScrollKey(opts.Key) {
509509
// we ignore click events on views that aren't popup panels, when a popup panel is focused.
510510
// Unless both the current view and the clicked-on view are either commit message or commit
511-
// description, because we want to allow switching between those two views by clicking.
512-
isCommitMessageView := func(viewName string) bool {
513-
return viewName == "commitMessage" || viewName == "commitDescription"
511+
// description, or a confirmation and the suggestions view, because we want to allow switching
512+
// between those two views by clicking.
513+
isCommitMessageOrSuggestionsView := func(viewName string) bool {
514+
return viewName == "commitMessage" || viewName == "commitDescription" ||
515+
viewName == "confirmation" || viewName == "suggestions"
514516
}
515-
if !isCommitMessageView(gui.currentViewName()) || !isCommitMessageView(binding.ViewName) {
517+
if !isCommitMessageOrSuggestionsView(gui.currentViewName()) || !isCommitMessageOrSuggestionsView(binding.ViewName) {
516518
return nil
517519
}
518520
}

0 commit comments

Comments
 (0)