lazygit/pkg/gui/controllers/search_prompt_controller.go
Jelte Fennema-Nio 9812d2fca4 Add return-alt1 to allow for a secondary Return key
This partially adds the feature back that was removed in #2495. This
allows specifing a secondary Return keybinding. In my personal setup I
use the `q` for this (and remove it as the default for Quit). Returning
is a very common operation in lazygit, and having to reach for the
Escape key all the time is annoying. There are cases where it's not
possible to use a regular letter as the Return keybinding, such as the
commit prompt.
2024-07-15 17:58:31 +02:00

78 lines
1.7 KiB
Go

package controllers
import (
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
type SearchPromptController struct {
baseController
c *ControllerCommon
}
var _ types.IController = &SearchPromptController{}
func NewSearchPromptController(
c *ControllerCommon,
) *SearchPromptController {
return &SearchPromptController{
baseController: baseController{},
c: c,
}
}
func (self *SearchPromptController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
return []*types.Binding{
{
Key: opts.GetKey(opts.Config.Universal.Confirm),
Modifier: gocui.ModNone,
Handler: self.confirm,
},
{
Key: opts.GetKey(opts.Config.Universal.Return),
Modifier: gocui.ModNone,
Handler: self.cancel,
},
{
Key: opts.GetKey(opts.Config.Universal.ReturnAlt1),
Modifier: gocui.ModNone,
Handler: self.cancel,
},
{
Key: opts.GetKey(opts.Config.Universal.PrevItem),
Modifier: gocui.ModNone,
Handler: self.prevHistory,
},
{
Key: opts.GetKey(opts.Config.Universal.NextItem),
Modifier: gocui.ModNone,
Handler: self.nextHistory,
},
}
}
func (self *SearchPromptController) Context() types.Context {
return self.context()
}
func (self *SearchPromptController) context() types.Context {
return self.c.Contexts().Search
}
func (self *SearchPromptController) confirm() error {
return self.c.Helpers().Search.Confirm()
}
func (self *SearchPromptController) cancel() error {
return self.c.Helpers().Search.CancelPrompt()
}
func (self *SearchPromptController) prevHistory() error {
self.c.Helpers().Search.ScrollHistory(1)
return nil
}
func (self *SearchPromptController) nextHistory() error {
self.c.Helpers().Search.ScrollHistory(-1)
return nil
}