mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-31 14:24:25 +03:00
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.
This commit is contained in:
@ -3,6 +3,7 @@ package controllers
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/jesseduffield/gocui"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
)
|
)
|
||||||
@ -51,6 +52,22 @@ func (self *ConfirmationController) GetKeybindings(opts types.KeybindingsOpts) [
|
|||||||
return bindings
|
return bindings
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *ConfirmationController) GetMouseKeybindings(opts types.KeybindingsOpts) []*gocui.ViewMouseBinding {
|
||||||
|
return []*gocui.ViewMouseBinding{
|
||||||
|
{
|
||||||
|
ViewName: self.c.Contexts().Suggestions.GetViewName(),
|
||||||
|
FocusedView: self.c.Contexts().Confirmation.GetViewName(),
|
||||||
|
Key: gocui.MouseLeft,
|
||||||
|
Handler: func(gocui.ViewMouseBindingOpts) error {
|
||||||
|
self.switchToSuggestions()
|
||||||
|
// Let it fall through to the ListController's click handler so that
|
||||||
|
// the clicked line gets selected:
|
||||||
|
return gocui.ErrKeybindingNotHandled
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (self *ConfirmationController) GetOnFocusLost() func(types.OnFocusLostOpts) {
|
func (self *ConfirmationController) GetOnFocusLost() func(types.OnFocusLostOpts) {
|
||||||
return func(types.OnFocusLostOpts) {
|
return func(types.OnFocusLostOpts) {
|
||||||
self.c.Helpers().Confirmation.DeactivateConfirmationPrompt()
|
self.c.Helpers().Confirmation.DeactivateConfirmationPrompt()
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/jesseduffield/gocui"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
)
|
)
|
||||||
@ -69,6 +70,19 @@ func (self *SuggestionsController) GetKeybindings(opts types.KeybindingsOpts) []
|
|||||||
return bindings
|
return bindings
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *SuggestionsController) GetMouseKeybindings(opts types.KeybindingsOpts) []*gocui.ViewMouseBinding {
|
||||||
|
return []*gocui.ViewMouseBinding{
|
||||||
|
{
|
||||||
|
ViewName: self.c.Contexts().Confirmation.GetViewName(),
|
||||||
|
FocusedView: self.c.Contexts().Suggestions.GetViewName(),
|
||||||
|
Key: gocui.MouseLeft,
|
||||||
|
Handler: func(gocui.ViewMouseBindingOpts) error {
|
||||||
|
return self.switchToConfirmation()
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (self *SuggestionsController) switchToConfirmation() error {
|
func (self *SuggestionsController) switchToConfirmation() error {
|
||||||
self.c.Views().Suggestions.Subtitle = ""
|
self.c.Views().Suggestions.Subtitle = ""
|
||||||
self.c.Views().Suggestions.Highlight = false
|
self.c.Views().Suggestions.Highlight = false
|
||||||
|
@ -508,11 +508,13 @@ func (gui *Gui) SetMouseKeybinding(binding *gocui.ViewMouseBinding) error {
|
|||||||
!gocui.IsMouseScrollKey(opts.Key) {
|
!gocui.IsMouseScrollKey(opts.Key) {
|
||||||
// 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.
|
||||||
// Unless both the current view and the clicked-on view are either commit message or commit
|
// 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.
|
// description, or a confirmation and the suggestions view, because we want to allow switching
|
||||||
isCommitMessageView := func(viewName string) bool {
|
// between those two views by clicking.
|
||||||
return viewName == "commitMessage" || viewName == "commitDescription"
|
isCommitMessageOrSuggestionsView := func(viewName string) bool {
|
||||||
|
return viewName == "commitMessage" || viewName == "commitDescription" ||
|
||||||
|
viewName == "confirmation" || viewName == "suggestions"
|
||||||
}
|
}
|
||||||
if !isCommitMessageView(gui.currentViewName()) || !isCommitMessageView(binding.ViewName) {
|
if !isCommitMessageOrSuggestionsView(gui.currentViewName()) || !isCommitMessageOrSuggestionsView(binding.ViewName) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user