diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2022-02-05 10:31:07 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2022-03-17 19:13:40 +1100 |
commit | 226985bf7602763f7578ef236bdc4cec3a1494e9 (patch) | |
tree | 3a12b9d41099902e411fe32df3b79d31e8a8f375 /pkg | |
parent | 2db463681564e8db945cd6811fc633545ee9fd83 (diff) |
refactor keybindings
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/gui/context/base_context.go | 24 | ||||
-rw-r--r-- | pkg/gui/context/commit_files_context.go | 2 | ||||
-rw-r--r-- | pkg/gui/context/list_context_trait.go | 29 | ||||
-rw-r--r-- | pkg/gui/context/tags_context.go | 2 | ||||
-rw-r--r-- | pkg/gui/context/working_tree_context.go | 2 | ||||
-rw-r--r-- | pkg/gui/controllers/bisect_controller.go | 7 | ||||
-rw-r--r-- | pkg/gui/controllers/files_controller.go | 44 | ||||
-rw-r--r-- | pkg/gui/controllers/local_commits_controller.go | 65 | ||||
-rw-r--r-- | pkg/gui/controllers/menu_controller.go | 11 | ||||
-rw-r--r-- | pkg/gui/controllers/remotes_controller.go | 15 | ||||
-rw-r--r-- | pkg/gui/controllers/submodules_controller.go | 21 | ||||
-rw-r--r-- | pkg/gui/controllers/sync_controller.go | 11 | ||||
-rw-r--r-- | pkg/gui/controllers/tags_controller.go | 17 | ||||
-rw-r--r-- | pkg/gui/controllers/undo_controller.go | 11 | ||||
-rw-r--r-- | pkg/gui/gui.go | 27 | ||||
-rw-r--r-- | pkg/gui/keybindings.go | 36 | ||||
-rw-r--r-- | pkg/gui/list_context.go | 35 | ||||
-rw-r--r-- | pkg/gui/list_context_config.go | 40 | ||||
-rw-r--r-- | pkg/gui/types/context.go | 17 |
19 files changed, 215 insertions, 201 deletions
diff --git a/pkg/gui/context/base_context.go b/pkg/gui/context/base_context.go index f6007fe5f..c61f57cf4 100644 --- a/pkg/gui/context/base_context.go +++ b/pkg/gui/context/base_context.go @@ -1,6 +1,8 @@ package context -import "github.com/jesseduffield/lazygit/pkg/gui/types" +import ( + "github.com/jesseduffield/lazygit/pkg/gui/types" +) type BaseContext struct { kind types.ContextKind @@ -9,9 +11,14 @@ type BaseContext struct { windowName string onGetOptionsMap func() map[string]string + keybindingsFns []types.KeybindingsFn + keybindings []*types.Binding + *ParentContextMgr } +var _ types.IBaseContext = &BaseContext{} + type NewBaseContextOpts struct { Kind types.ContextKind Key types.ContextKey @@ -58,3 +65,18 @@ func (self *BaseContext) GetKind() types.ContextKind { func (self *BaseContext) GetKey() types.ContextKey { return self.key } + +func (self *BaseContext) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding { + bindings := []*types.Binding{} + for i := range self.keybindingsFns { + // the first binding in the bindings array takes precedence but we want the + // last keybindingsFn to take precedence to we add them in reverse + bindings = append(bindings, self.keybindingsFns[len(self.keybindingsFns)-1-i](opts)...) + } + + return bindings +} + +func (self *BaseContext) AddKeybindingsFn(fn types.KeybindingsFn) { + self.keybindingsFns = append(self.keybindingsFns, fn) +} diff --git a/pkg/gui/context/commit_files_context.go b/pkg/gui/context/commit_files_context.go index dd557f6b2..49a9f34da 100644 --- a/pkg/gui/context/commit_files_context.go +++ b/pkg/gui/context/commit_files_context.go @@ -55,6 +55,8 @@ func NewCommitFilesContext( c: c, } + baseContext.AddKeybindingsFn(listContextTrait.keybindings) + self.BaseContext = baseContext self.ListContextTrait = listContextTrait self.CommitFileTreeViewModel = viewModel diff --git a/pkg/gui/context/list_context_trait.go b/pkg/gui/context/list_context_trait.go index c1d45eb4e..50a91b827 100644 --- a/pkg/gui/context/list_context_trait.go +++ b/pkg/gui/context/list_context_trait.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/jesseduffield/gocui" - "github.com/jesseduffield/lazygit/pkg/config" "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/utils" ) @@ -182,32 +181,28 @@ func (self *ListContextTrait) HandleRenderToMain() error { return nil } -func (self *ListContextTrait) Keybindings( - getKey func(key string) interface{}, - config config.KeybindingConfig, - guards types.KeybindingGuards, -) []*types.Binding { +func (self *ListContextTrait) keybindings(opts types.KeybindingsOpts) []*types.Binding { return []*types.Binding{ - {Tag: "navigation", Key: getKey(config.Universal.PrevItemAlt), Modifier: gocui.ModNone, Handler: self.HandlePrevLine}, - {Tag: "navigation", Key: getKey(config.Universal.PrevItem), Modifier: gocui.ModNone, Handler: self.HandlePrevLine}, + {Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.PrevItemAlt), Modifier: gocui.ModNone, Handler: self.HandlePrevLine}, + {Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.PrevItem), Modifier: gocui.ModNone, Handler: self.HandlePrevLine}, {Tag: "navigation", Key: gocui.MouseWheelUp, Modifier: gocui.ModNone, Handler: self.HandlePrevLine}, - {Tag: "navigation", Key: getKey(config.Universal.NextItemAlt), Modifier: gocui.ModNone, Handler: self.HandleNextLine}, - {Tag: "navigation", Key: getKey(config.Universal.NextItem), Modifier: gocui.ModNone, Handler: self.HandleNextLine}, - {Tag: "navigation", Key: getKey(config.Universal.PrevPage), Modifier: gocui.ModNone, Handler: self.HandlePrevPage, Description: self.c.Tr.LcPrevPage}, - {Tag: "navigation", Key: getKey(config.Universal.NextPage), Modifier: gocui.ModNone, Handler: self.HandleNextPage, Description: self.c.Tr.LcNextPage}, - {Tag: "navigation", Key: getKey(config.Universal.GotoTop), Modifier: gocui.ModNone, Handler: self.HandleGotoTop, Description: self.c.Tr.LcGotoTop}, + {Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.NextItemAlt), Modifier: gocui.ModNone, Handler: self.HandleNextLine}, + {Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.NextItem), Modifier: gocui.ModNone, Handler: self.HandleNextLine}, + {Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.PrevPage), Modifier: gocui.ModNone, Handler: self.HandlePrevPage, Description: self.c.Tr.LcPrevPage}, + {Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.NextPage), Modifier: gocui.ModNone, Handler: self.HandleNextPage, Description: self.c.Tr.LcNextPage}, + {Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.GotoTop), Modifier: gocui.ModNone, Handler: self.HandleGotoTop, Description: self.c.Tr.LcGotoTop}, {Key: gocui.MouseLeft, Modifier: gocui.ModNone, Handler: func() error { return self.HandleClick(nil) }}, {Tag: "navigation", Key: gocui.MouseWheelDown, Modifier: gocui.ModNone, Handler: self.HandleNextLine}, - {Tag: "navigation", Key: getKey(config.Universal.ScrollLeft), Modifier: gocui.ModNone, Handler: self.HandleScrollLeft}, - {Tag: "navigation", Key: getKey(config.Universal.ScrollRight), Modifier: gocui.ModNone, Handler: self.HandleScrollRight}, + {Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.ScrollLeft), Modifier: gocui.ModNone, Handler: self.HandleScrollLeft}, + {Tag: "navigation", Key: opts.GetKey(opts.Config.Universal.ScrollRight), Modifier: gocui.ModNone, Handler: self.HandleScrollRight}, { - Key: getKey(config.Universal.StartSearch), + Key: opts.GetKey(opts.Config.Universal.StartSearch), Handler: func() error { self.c.OpenSearch(); return nil }, Description: self.c.Tr.LcStartSearch, Tag: "navigation", }, { - Key: getKey(config.Universal.GotoBottom), + Key: opts.GetKey(opts.Config.Universal.GotoBottom), Description: self.c.Tr.LcGotoBottom, Handler: self.HandleGotoBottom, Tag: "navigation", diff --git a/pkg/gui/context/tags_context.go b/pkg/gui/context/tags_context.go index fc6e1bde1..8644b15dc 100644 --- a/pkg/gui/context/tags_context.go +++ b/pkg/gui/context/tags_context.go @@ -55,6 +55,8 @@ func NewTagsContext( c: c, } + baseContext.AddKeybindingsFn(listContextTrait.keybindings) + self.BaseContext = baseContext self.ListContextTrait = listContextTrait self.TagsViewModel = list diff --git a/pkg/gui/context/working_tree_context.go b/pkg/gui/context/working_tree_context.go index fafddf9e8..8ab4a1403 100644 --- a/pkg/gui/context/working_tree_context.go +++ b/pkg/gui/context/working_tree_context.go @@ -55,6 +55,8 @@ func NewWorkingTreeContext( c: c, } + baseContext.AddKeybindingsFn(listContextTrait.keybindings) + self.BaseContext = baseContext self.ListContextTrait = listContextTrait self.FileTreeViewModel = viewModel diff --git a/pkg/gui/controllers/bisect_controller.go b/pkg/gui/controllers/bisect_controller.go index bb7ba642d..9841b5e59 100644 --- a/pkg/gui/controllers/bisect_controller.go +++ b/pkg/gui/controllers/bisect_controller.go @@ -7,7 +7,6 @@ import ( "github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/commands/git_commands" "github.com/jesseduffield/lazygit/pkg/commands/models" - "github.com/jesseduffield/lazygit/pkg/config" "github.com/jesseduffield/lazygit/pkg/gui/types" ) @@ -43,11 +42,11 @@ func NewBisectController( } } -func (self *BisectController) Keybindings(getKey func(key string) interface{}, config config.KeybindingConfig, guards types.KeybindingGuards) []*types.Binding { +func (self *BisectController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding { bindings := []*types.Binding{ { - Key: getKey(config.Commits.ViewBisectOptions), - Handler: guards.OutsideFilterMode(self.checkSelected(self.openMenu)), + Key: opts.GetKey(opts.Config.Commits.ViewBisectOptions), + Handler: opts.Guards.OutsideFilterMode(self.checkSelected(self.openMenu)), Description: self.c.Tr.LcViewBisectOptions, OpensMenu: true, }, diff --git a/pkg/gui/controllers/files_controller.go b/pkg/gui/controllers/files_controller.go index a7c4ff374..1f9521867 100644 --- a/pkg/gui/controllers/files_controller.go +++ b/pkg/gui/controllers/files_controller.go @@ -87,10 +87,10 @@ func NewFilesController( } } -func (self *FilesController) Keybindings(getKey func(key string) interface{}, config config.KeybindingConfig, guards types.KeybindingGuards) []*types.Binding { - bindings := []*types.Binding{ +func (self *FilesController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding { + return []*types.Binding{ { - Key: getKey(config.Universal.Select), + Key: opts.GetKey(opts.Config.Universal.Select), Handler: self.checkSelectedFileNode(self.press), Description: self.c.Tr.LcToggleStaged, }, @@ -99,103 +99,101 @@ func (self *FilesController) Keybindings(getKey func(key string) interface{}, co Handler: func() error { return self.context.HandleClick(self.checkSelectedFileNode(self.press)) }, }, { - Key: getKey("<c-b>"), // TODO: softcode + Key: opts.GetKey("<c-b>"), // TODO: softcode Handler: self.handleStatusFilterPressed, Description: self.c.Tr.LcFileFilter, }, { - Key: getKey(config.Files.CommitChanges), + Key: opts.GetKey(opts.Config.Files.CommitChanges), Handler: self.HandleCommitPress, Description: self.c.Tr.CommitChanges, }, { - Key: getKey(config.Files.CommitChangesWithoutHook), + Key: opts.GetKey(opts.Config.Files.CommitChangesWithoutHook), Handler: self.HandleWIPCommitPress, Description: self.c.Tr.LcCommitChangesWithoutHook, }, { - Key: getKey(config.Files.AmendLastCommit), + Key: opts.GetKey(opts.Config.Files.AmendLastCommit), Handler: self.handleAmendCommitPress, Description: self.c.Tr.AmendLastCommit, }, { - Key: getKey(config.Files.CommitChangesWithEditor), + Key: opts.GetKey(opts.Config.Files.CommitChangesWithEditor), Handler: self.HandleCommitEditorPress, Description: self.c.Tr.CommitChangesWithEditor, }, { - Key: getKey(config.Universal.Edit), + Key: opts.GetKey(opts.Config.Universal.Edit), Handler: self.checkSelectedFileNode(self.edit), Description: self.c.Tr.LcEditFile, }, { - Key: getKey(config.Universal.OpenFile), + Key: opts.GetKey(opts.Config.Universal.OpenFile), Handler: self.Open, Description: self.c.Tr.LcOpenFile, }, { - Key: getKey(config.Files.IgnoreFile), + Key: opts.GetKey(opts.Config.Files.IgnoreFile), Handler: self.checkSelectedFileNode(self.ignore), Description: self.c.Tr.LcIgnoreFile, }, { - Key: getKey(config.Universal.Remove), + Key: opts.GetKey(opts.Config.Universal.Remove), Handler: self.checkSelectedFileNode(self.remove), Description: self.c.Tr.LcViewDiscardOptions, OpensMenu: true, }, { - Key: getKey(config.Files.RefreshFiles), + Key: opts.GetKey(opts.Config.Files.RefreshFiles), Handler: self.refresh, Description: self.c.Tr.LcRefreshFiles, }, { - Key: getKey(config.Files.StashAllChanges), + Key: opts.GetKey(opts.Config.Files.StashAllChanges), Handler: self.stash, Description: self.c.Tr.LcStashAllChanges, }, { - Key: getKey(config.Files.ViewStashOptions), + Key: opts.GetKey(opts.Config.Files.ViewStashOptions), Handler: self.createStashMenu, Description: self.c.Tr.LcViewStashOptions, OpensMenu: true, }, { - Key: getKey(config.Files.ToggleStagedAll), + Key: opts.GetKey(opts.Config.Files.ToggleStagedAll), Handler: self.stageAll, Description: self.c.Tr.LcToggleStagedAll, }, { - Key: getKey(config.Universal.GoInto), + Key: opts.GetKey(opts.Config.Universal.GoInto), Handler: self.enter, Description: self.c.Tr.FileEnter, }, { ViewName: "", - Key: getKey(config.Universal.ExecuteCustomCommand), + Key: opts.GetKey(opts.Config.Universal.ExecuteCustomCommand), Handler: self.handleCustomCommand, Description: self.c.Tr.LcExecuteCustomCommand, }, { - Key: getKey(config.Commits.ViewResetOptions), + Key: opts.GetKey(opts.Config.Commits.ViewResetOptions), Handler: self.createResetMenu, Description: self.c.Tr.LcViewResetToUpstreamOptions, OpensMenu: true, }, // here { - Key: getKey(config.Files.ToggleTreeView), + Key: opts.GetKey(opts.Config.Files.ToggleTreeView), Handler: self.toggleTreeView, Description: self.c.Tr.LcToggleTreeView, }, { - Key: getKey(config.Files.OpenMergeTool), + Key: opts.GetKey(opts.Config.Files.OpenMergeTool), Handler: self.OpenMergeTool, Description: self.c.Tr.LcOpenMergeTool, }, } - - return append(bindings, self.context.Keybindings(getKey, config, guards)...) } func (self *FilesController) press(node *filetree.FileNode) error { diff --git a/pkg/gui/controllers/local_commits_controller.go b/pkg/gui/controllers/local_commits_controller.go index 749199c1e..5458697e3 100644 --- a/pkg/gui/controllers/local_commits_controller.go +++ b/pkg/gui/controllers/local_commits_controller.go @@ -8,7 +8,6 @@ import ( "github.com/jesseduffield/lazygit/pkg/commands/hosting_service" "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/commands/oscommands" - "github.com/jesseduffield/lazygit/pkg/config" "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/utils" ) @@ -91,108 +90,104 @@ func NewLocalCommitsController( } } -func (self *LocalCommitsController) Keybindings( - getKey func(key string) interface{}, - config config.KeybindingConfig, - guards types.KeybindingGuards, -) []*types.Binding { +func (self *LocalCommitsController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding { outsideFilterModeBindings := []*types.Binding{ { - Key: getKey(config.Commits.SquashDown), + Key: opts.GetKey(opts.Config.Commits.SquashDown), Handler: self.squashDown, Description: self.c.Tr.LcSquashDown, }, { - Key: getKey(config.Commits.MarkCommitAsFixup), + Key: opts.GetKey(opts.Config.Commits.MarkCommitAsFixup), Handler: self.fixup, Description: self.c.Tr.LcFixupCommit, }, { - Key: getKey(config.Commits.RenameCommit), + Key: opts.GetKey(opts.Config.Commits.RenameCommit), Handler: self.checkSelected(self.reword), Description: self.c.Tr.LcRewordCommit, }, { - Key: getKey(config.Commits.RenameCommitWithEditor), + Key: opts.GetKey(opts.Config.Commits.RenameCommitWithEditor), Handler: self.rewordEditor, Description: self.c.Tr.LcRenameCommitEditor, }, { - Key: getKey(config.Universal.Remove), + Key: opts.GetKey(opts.Config.Universal.Remove), Handler: self.drop, Description: self.c.Tr.LcDeleteCommit, }, { - Key: getKey(config.Universal.Edit), + Key: opts.GetKey(opts.Config.Universal.Edit), Handler: self.edit, Description: self.c.Tr.LcEditCommit, }, { - Key: getKey(config.Commits.PickCommit), + Key: opts.GetKey(opts.Config.Commits.PickCommit), Handler: self.pick, Description: self.c.Tr.LcPickCommit, }, { - Key: getKey(config.Commits.CreateFixupCommit), + Key: opts.GetKey(opts.Config.Commits.CreateFixupCommit), Handler: self.checkSelected(self.handleCreateFixupCommit), Description: self.c.Tr.LcCreateFixupCommit, }, { - Key: getKey(config.Commits.SquashAboveCommits), + Key: opts.GetKey(opts.Config.Commits.SquashAboveCommits), Handler: self.checkSelected(self.handleSquashAllAboveFixupCommits), Description: self.c.Tr.LcSquashAboveCommits, }, { - Key: getKey(config.Commits.MoveDownCommit), + Key: opts.GetKey(opts.Config.Commits.MoveDownCommit), Handler: self.handleCommitMoveDown, Description: self.c.Tr.LcMoveDownCommit, }, { - Key: getKey(config.Commits.MoveUpCommit), + Key: opts.GetKey(opts.Config.Commits.MoveUpCommit), Handler: self.handleCommitMoveUp, Description: self.c.Tr.LcMoveUpCommit, }, { - Key: getKey(config.Commits.AmendToCommit), + Key: opts.GetKey(opts.Config.Commits.AmendToCommit), Handler: self.handleCommitAmendTo, Description: self.c.Tr.LcAmendToCommit, }, { - Key: getKey(config.Commits.RevertCommit), + Key: opts.GetKey(opts.Config.Commits.RevertCommit), Handler: self.checkSelected(self.handleCommitRevert), Description: self.c.Tr.LcRevertCommit, }, { - Key: getKey(config.Universal.New), + Key: opts.GetKey(opts.Config.Universal.New), Modifier: gocui.ModNone, Handler: self.checkSelected(self.newBranch), Description: self.c.Tr.LcCreateNewBranchFromCommit, }, { - Key: getKey(config.Commits.CherryPickCopy), + Key: opts.GetKey(opts.Config.Commits.CherryPickCopy), Handler: self.checkSelected(self.copy), Description: self.c.Tr.LcCherryPickCopy, }, { - Key: getKey(config.Commits.CherryPickCopyRange), + Key: opts.GetKey(opts.Config.Commits.CherryPickCopyRange), Handler: self.checkSelected(self.copyRange), Description: self.c.Tr.LcCherryPickCopyRange, }, { - Key: getKey(config.Commits.PasteCommits), - Handler: guards.OutsideFilterMode(self.paste), + Key: opts.GetKey(opts.Config.Commits.PasteCommits), + Handler: opts.Guards.OutsideFilterMode(self.paste), Description: self.c.Tr.LcPasteCommits, }, // overriding these navigation keybindings because we might need to load // more commits on demand { - Key: getKey(config.Universal.StartSearch), + Key: opts.GetKey(opts.Config.Universal.StartSearch), Handler: self.openSearch, Description: self.c.Tr.LcStartSearch, Tag: "navigation", }, { - Key: getKey(config.Universal.GotoBottom), + Key: opts.GetKey(opts.Config.Universal.GotoBottom), Handler: self.gotoBottom, Description: self.c.Tr.LcGotoBottom, Tag: "navigation", @@ -204,49 +199,49 @@ func (self *LocalCommitsController) Keybindings( } for _, binding := range outsideFilterModeBindings { - binding.Handler = guards.OutsideFilterMode(binding.Handler) + binding.Handler = opts.Guards.OutsideFilterMode(binding.Handler) } bindings := append(outsideFilterModeBindings, []*types.Binding{ { - Key: getKey(config.Commits.OpenLogMenu), + Key: opts.GetKey(opts.Config.Commits.OpenLogMenu), Handler: self.handleOpenLogMenu, Description: self.c.Tr.LcOpenLogMenu, OpensMenu: true, }, { - Key: getKey(config.Commits.ViewResetOptions), + Key: opts.GetKey(opts.Config.Commits.ViewResetOptions), Handler: self.checkSelected(self.handleCreateCommitResetMenu), Description: self.c.Tr.LcResetToThisCommit, }, { - Key: getKey(config.Universal.GoInto), + Key: opts.GetKey(opts.Config.Universal.GoInto), Handler: self.checkSelected(self.enter), Description: self.c.Tr.LcViewCommitFiles, }, { - Key: getKey(config.Commits.CheckoutCommit), + Key: opts.GetKey(opts.Config.Commits.CheckoutCommit), Handler: self.checkSelected(self.handleCheckoutCommit), Description: self.c.Tr.LcCheckoutCommit, }, { - Key: getKey(config.Commits.TagCommit), + Key: opts.GetKey(opts.Config.Commits.TagCommit), Handler: self.checkSelected(self.handleTagCommit), Description: self.c.Tr.LcTagCommit, }, { - Key: getKey(config.Commits.CopyCommitMessageToClipboard), + Key: opts.GetKey(opts.Config.Commits.CopyCommitMessageToClipboard), Handler: self.checkSelected(self.handleCopySelectedCommitMessageToClipboard), Description: self.c.Tr.LcCopyCommitMessageToClipboard, }, { - Key: getKey(config.Commits.OpenInBrowser), + Key: opts.GetKey(opts.Config.Commits.OpenInBrowser), Handler: self.checkSelected(self.handleOpenCommitInBrowser), Description: self.c.Tr.LcOpenCommitInBrowser, }, }...) - return append(bindings, self.context.Keybindings(getKey, config, guards)...) + return bindings } func (self *LocalCommitsController) squashDown() error { diff --git a/pkg/gui/controllers/menu_controller.go b/pkg/gui/controllers/menu_controller.go index 7773a0148..7c93ef6f7 100644 --- a/pkg/gui/controllers/menu_controller.go +++ b/pkg/gui/controllers/menu_controller.go @@ -2,7 +2,6 @@ package controllers import ( "github.com/jesseduffield/gocui" - "github.com/jesseduffield/lazygit/pkg/config" "github.com/jesseduffield/lazygit/pkg/gui/types" ) @@ -27,18 +26,18 @@ func NewMenuController( } } -func (self *MenuController) Keybindings(getKey func(key string) interface{}, config config.KeybindingConfig, guards types.KeybindingGuards) []*types.Binding { +func (self *MenuController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding { bindings := []*types.Binding{ { - Key: getKey(config.Universal.Select), + Key: opts.GetKey(opts.Config.Universal.Select), Handler: self.press, }, { - Key: getKey(config.Universal.Confirm), + Key: opts.GetKey(opts.Config.Universal.Confirm), Handler: self.press, }, { - Key: getKey(config.Universal.ConfirmAlt1), + Key: opts.GetKey(opts.Config.Universal.ConfirmAlt1), Handler: self.press, }, { @@ -47,7 +46,7 @@ func (self *MenuController) Keybindings(getKey func(key string) interface{}, con }, } - return append(bindings, self.context.Keybindings(getKey, config, guards)...) + return bindings } func (self *MenuController) press() error { diff --git a/pkg/gui/controllers/remotes_controller.go b/pkg/gui/controllers/remotes_controller.go index d9812d213..9f7acb9d0 100644 --- a/pkg/gui/controllers/remotes_controller.go +++ b/pkg/gui/controllers/remotes_controller.go @@ -4,7 +4,6 @@ import ( "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/commands/models" - "github.com/jesseduffield/lazygit/pkg/config" "github.com/jesseduffield/lazygit/pkg/gui/context" "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/utils" @@ -40,10 +39,10 @@ func NewRemotesController( } } -func (self *RemotesController) Keybindings(getKey func(key string) interface{}, config config.KeybindingConfig, guards types.KeybindingGuards) []*types.Binding { +func (self *RemotesController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding { bindings := []*types.Binding{ { - Key: getKey(config.Universal.GoInto), + Key: opts.GetKey(opts.Config.Universal.GoInto), Handler: self.checkSelected(self.enter), }, { @@ -51,28 +50,28 @@ func (self *RemotesController) Keybindings(getKey func(key string) interface{}, Handler: func() error { return self.context.HandleClick(self.checkSelected(self.enter)) }, }, { - Key: getKey(config.Branches.FetchRemote), + Key: opts.GetKey(opts.Config.Branches.FetchRemote), Handler: self.checkSelected(self.fetch), Description: self.c.Tr.LcFetchRemote, }, { - Key: getKey(config.Universal.New), + Key: opts.GetKey(opts.Config.Universal.New), Handler: self.add, Description: self.c.Tr.LcAddNewRemote, }, { - Key: getKey(config.Universal.Remove), + Key: opts.GetKey(opts.Config.Universal.Remove), Handler: self.checkSelected(self.remove), Description: self.c.Tr.LcRemoveRemote, }, { - Key: getKey(config.Universal.Edit), + Key: opts.GetKey(opts.Config.Universal.Edit), Handler: self.checkSelected(self.edit), Description: self.c.Tr.LcEditRemote, }, } - return append(bindings, self.context.Keybindings(getKey, config, guards)...) + return bindings } func (self *RemotesController) enter(remote *models.Remote) error { diff --git a/pkg/gui/controllers/submodules_controller.go b/pkg/gui/controllers/submodules_controller.go index 851d11983..f1ac7acf3 100644 --- a/pkg/gui/controllers/submodules_controller.go +++ b/pkg/gui/controllers/submodules_controller.go @@ -8,7 +8,6 @@ import ( "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/commands/models" - "github.com/jesseduffield/lazygit/pkg/config" "github.com/jesseduffield/lazygit/pkg/gui/style" "github.com/jesseduffield/lazygit/pkg/gui/types" ) @@ -40,40 +39,40 @@ func NewSubmodulesController( } } -func (self *SubmodulesController) Keybindings(getKey func(key string) interface{}, config config.KeybindingConfig, guards types.KeybindingGuards) []*types.Binding { - bindings := []*types.Binding{ +func (self *SubmodulesController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding { + return []*types.Binding{ { - Key: getKey(config.Universal.GoInto), + Key: opts.GetKey(opts.Config.Universal.GoInto), Handler: self.checkSelected(self.enter), Description: self.c.Tr.LcEnterSubmodule, }, { - Key: getKey(config.Universal.Remove), + Key: opts.GetKey(opts.Config.Universal.Remove), Handler: self.checkSelected(self.remove), Description: self.c.Tr.LcRemoveSubmodule, }, { - Key: getKey(config.Submodules.Update), + Key: opts.GetKey(opts.Config.Submodules.Update), Handler: self.checkSelected(self.update), Description: self.c.Tr.LcSubmoduleUpdate, }, { - Key: getKey(config.Universal.New), + Key: opts.GetKey(opts.Config.Universal.New), Handler: self.add, Description: self.c.Tr.LcAddSubmodule, }, { - Key: getKey(config.Universal.Edit), + Key: opts.GetKey(opts.Config.Universal.Edit), Handler: self.checkSelected(self.editURL), Description: self.c.Tr.LcEditSubmoduleUrl, }, { - Key: getKey(config.Submodules.Init), + Key: opts.GetKey(opts.Config.Submodules.Init), Handler: self.checkSelected(self.init), Description: self.c.Tr.LcInitSubmodule, }, { - Key: getKey(config.Submodules.BulkMenu), + Key: opts.GetKey(opts.Config.Submodules.BulkMenu), Handler: self.openBulkActionsMenu, Description: self.c.Tr.LcViewBulkSubmoduleOptions, OpensMenu: true, @@ -83,8 +82,6 @@ func (self *SubmodulesController) Keybindings(getKey func(key string) interface{ Handler: func() error { return self.context.HandleClick(self.checkSelected(self.enter)) }, }, } - - return append(bindings, self.context.Keybindings(getKey, config, guards)...) } func (self *SubmodulesController) enter(submodule *models.SubmoduleConfig) error { diff --git a/pkg/gui/controllers/sync_controller.go b/pkg/gui/controllers/sync_controller.go index 582d8a9de..106b4c516 100644 --- a/pkg/gui/controllers/sync_controller.go +++ b/pkg/gui/controllers/sync_controller.go @@ -7,7 +7,6 @@ import ( "github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/commands/git_commands" "github.com/jesseduffield/lazygit/pkg/commands/models" - "github.com/jesseduffield/lazygit/pkg/config" "github.com/jesseduffield/lazygit/pkg/gui/types" ) @@ -46,16 +45,16 @@ func NewSyncController( } } -func (self *SyncController) Keybindings(getKey func(key string) interface{}, config config.KeybindingConfig, guards types.KeybindingGuards) []*types.Binding { +func ( |