mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-10 15:46:26 -04:00
Two places nudged the flags because nothing else would: switching repos, where the view focused in the repo being left is not the one focused in the repo being entered, and tabbing from the suggestions list back to the prompt, which replaces the top of the stack rather than popping it, so the suggestions context never hears that it lost the focus. Both are just a context leaving the stack now. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
101 lines
2.8 KiB
Go
101 lines
2.8 KiB
Go
package controllers
|
|
|
|
import (
|
|
"github.com/jesseduffield/lazygit/pkg/gocui"
|
|
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
|
)
|
|
|
|
type SuggestionsController struct {
|
|
baseController
|
|
*ListControllerTrait[*types.Suggestion]
|
|
c *ControllerCommon
|
|
}
|
|
|
|
var _ types.IController = &SuggestionsController{}
|
|
|
|
func NewSuggestionsController(
|
|
c *ControllerCommon,
|
|
) *SuggestionsController {
|
|
return &SuggestionsController{
|
|
baseController: baseController{},
|
|
ListControllerTrait: NewListControllerTrait(
|
|
c,
|
|
c.Contexts().Suggestions,
|
|
c.Contexts().Suggestions.GetSelected,
|
|
c.Contexts().Suggestions.GetSelectedItems,
|
|
),
|
|
c: c,
|
|
}
|
|
}
|
|
|
|
func (self *SuggestionsController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
|
|
bindings := []*types.Binding{
|
|
{
|
|
Keys: opts.GetKeys(opts.Config.Universal.ConfirmSuggestion),
|
|
Handler: func() error { return self.context().State.OnConfirm() },
|
|
GetDisabledReason: self.require(self.singleItemSelected()),
|
|
},
|
|
{
|
|
Keys: opts.GetKeys(opts.Config.Universal.Return),
|
|
Handler: func() error { return self.context().State.OnClose() },
|
|
},
|
|
{
|
|
Keys: opts.GetKeys(opts.Config.Universal.TogglePanel),
|
|
Handler: self.switchToPrompt,
|
|
},
|
|
{
|
|
Keys: opts.GetKeys(opts.Config.Universal.Remove),
|
|
Handler: func() error {
|
|
return self.context().State.OnDeleteSuggestion()
|
|
},
|
|
},
|
|
{
|
|
Keys: opts.GetKeys(opts.Config.Universal.Edit),
|
|
Handler: func() error {
|
|
if self.context().State.AllowEditSuggestion {
|
|
if selectedItem := self.c.Contexts().Suggestions.GetSelected(); selectedItem != nil {
|
|
self.c.Contexts().Prompt.GetView().TextArea.Clear()
|
|
self.c.Contexts().Prompt.GetView().TextArea.TypeString(selectedItem.Value)
|
|
self.c.Contexts().Prompt.GetView().RenderTextArea()
|
|
self.c.Contexts().Suggestions.RefreshSuggestions()
|
|
return self.switchToPrompt()
|
|
}
|
|
}
|
|
return nil
|
|
},
|
|
},
|
|
}
|
|
|
|
return bindings
|
|
}
|
|
|
|
func (self *SuggestionsController) GetMouseKeybindings(opts types.KeybindingsOpts) []*gocui.ViewMouseBinding {
|
|
return []*gocui.ViewMouseBinding{
|
|
{
|
|
ViewName: self.c.Contexts().Prompt.GetViewName(),
|
|
FocusedView: self.c.Contexts().Suggestions.GetViewName(),
|
|
Key: gocui.MouseLeft,
|
|
Handler: func(gocui.ViewMouseBindingOpts) error {
|
|
return self.switchToPrompt()
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func (self *SuggestionsController) switchToPrompt() error {
|
|
self.c.Views().Suggestions.Subtitle = ""
|
|
self.c.Context().Replace(self.c.Contexts().Prompt)
|
|
return nil
|
|
}
|
|
|
|
func (self *SuggestionsController) GetOnFocusLost() func(types.OnFocusLostOpts) {
|
|
return func(types.OnFocusLostOpts) {
|
|
self.c.Helpers().Confirmation.DeactivatePrompt()
|
|
}
|
|
}
|
|
|
|
func (self *SuggestionsController) context() *context.SuggestionsContext {
|
|
return self.c.Contexts().Suggestions
|
|
}
|