mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-05 00:59:19 +02:00
Make custom commands reload when switching repos
Since onNewRepo calls resetKeybindings, which reinitializes the keybindings for custom commands, all we have to do for this is store a pointer to a config instead of storing the customCommands, so we get the up-to-date ones every time.
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
package custom_commands
|
package custom_commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/jesseduffield/lazygit/pkg/config"
|
"github.com/jesseduffield/lazygit/pkg/common"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
|
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
)
|
)
|
||||||
@ -9,7 +9,7 @@ import (
|
|||||||
// Client is the entry point to this package. It returns a list of keybindings based on the config's user-defined custom commands.
|
// Client is the entry point to this package. It returns a list of keybindings based on the config's user-defined custom commands.
|
||||||
// See https://github.com/jesseduffield/lazygit/blob/master/docs/Custom_Command_Keybindings.md for more info.
|
// See https://github.com/jesseduffield/lazygit/blob/master/docs/Custom_Command_Keybindings.md for more info.
|
||||||
type Client struct {
|
type Client struct {
|
||||||
customCommands []config.CustomCommand
|
c *common.Common
|
||||||
handlerCreator *HandlerCreator
|
handlerCreator *HandlerCreator
|
||||||
keybindingCreator *KeybindingCreator
|
keybindingCreator *KeybindingCreator
|
||||||
}
|
}
|
||||||
@ -26,10 +26,9 @@ func NewClient(
|
|||||||
helpers.MergeAndRebase,
|
helpers.MergeAndRebase,
|
||||||
)
|
)
|
||||||
keybindingCreator := NewKeybindingCreator(c)
|
keybindingCreator := NewKeybindingCreator(c)
|
||||||
customCommands := c.UserConfig().CustomCommands
|
|
||||||
|
|
||||||
return &Client{
|
return &Client{
|
||||||
customCommands: customCommands,
|
c: c.Common,
|
||||||
keybindingCreator: keybindingCreator,
|
keybindingCreator: keybindingCreator,
|
||||||
handlerCreator: handlerCreator,
|
handlerCreator: handlerCreator,
|
||||||
}
|
}
|
||||||
@ -37,7 +36,7 @@ func NewClient(
|
|||||||
|
|
||||||
func (self *Client) GetCustomCommandKeybindings() ([]*types.Binding, error) {
|
func (self *Client) GetCustomCommandKeybindings() ([]*types.Binding, error) {
|
||||||
bindings := []*types.Binding{}
|
bindings := []*types.Binding{}
|
||||||
for _, customCommand := range self.customCommands {
|
for _, customCommand := range self.c.UserConfig().CustomCommands {
|
||||||
handler := self.handlerCreator.call(customCommand)
|
handler := self.handlerCreator.call(customCommand)
|
||||||
compoundBindings, err := self.keybindingCreator.call(customCommand, handler)
|
compoundBindings, err := self.keybindingCreator.call(customCommand, handler)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Reference in New Issue
Block a user