diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2022-02-13 10:39:14 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2022-03-17 19:13:40 +1100 |
commit | 3188526ecb1e48327249a830173de7ab5ce5978a (patch) | |
tree | 559223336c868f2553057fb1cdeaf0d6e2600df7 /pkg | |
parent | 722410aded4e3d14356c7ab94bfa15abe10359fa (diff) |
fix cheatsheet crash
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/cheatsheet/generate.go | 2 | ||||
-rw-r--r-- | pkg/gui/controllers/helpers/helpers.go | 14 | ||||
-rw-r--r-- | pkg/gui/keybindings.go | 13 |
3 files changed, 26 insertions, 3 deletions
diff --git a/pkg/cheatsheet/generate.go b/pkg/cheatsheet/generate.go index f499a2f58..47de22a40 100644 --- a/pkg/cheatsheet/generate.go +++ b/pkg/cheatsheet/generate.go @@ -124,7 +124,7 @@ func formatBinding(binding *types.Binding) string { func getBindingSections(mApp *app.App) []*bindingSection { bindingSections := []*bindingSection{} - bindings, _ := mApp.Gui.GetInitialKeybindings() + bindings := mApp.Gui.GetCheatsheetKeybindings() type contextAndViewType struct { subtitle string diff --git a/pkg/gui/controllers/helpers/helpers.go b/pkg/gui/controllers/helpers/helpers.go index 65f686ade..2ca4fbd40 100644 --- a/pkg/gui/controllers/helpers/helpers.go +++ b/pkg/gui/controllers/helpers/helpers.go @@ -11,3 +11,17 @@ type Helpers struct { CherryPick *CherryPickHelper Host *HostHelper } + +func NewStubHelpers() *Helpers { + return &Helpers{ + Refs: &RefsHelper{}, + Bisect: &BisectHelper{}, + Suggestions: &SuggestionsHelper{}, + Files: &FilesHelper{}, + WorkingTree: &WorkingTreeHelper{}, + Tags: &TagsHelper{}, + MergeAndRebase: &MergeAndRebaseHelper{}, + CherryPick: &CherryPickHelper{}, + Host: &HostHelper{}, + } +} diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 25433eca5..a2dd7a419 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -10,6 +10,7 @@ import ( "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/constants" "github.com/jesseduffield/lazygit/pkg/gui/context" + "github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers" "github.com/jesseduffield/lazygit/pkg/gui/types" ) @@ -194,6 +195,16 @@ func (gui *Gui) noPopupPanel(f func() error) func() error { } } +// only to be called from the cheatsheet generate script. This mutates the Gui struct. +func (self *Gui) GetCheatsheetKeybindings() []*types.Binding { + self.helpers = helpers.NewStubHelpers() + self.State = &GuiRepoState{} + self.State.Contexts = self.contextTree() + self.resetControllers() + bindings, _ := self.GetInitialKeybindings() + return bindings +} + // renaming receiver to 'self' to aid refactoring. Will probably end up moving all Gui handlers to this pattern eventually. func (self *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBinding) { config := self.c.UserConfig.Keybinding @@ -1306,8 +1317,6 @@ func (self *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBi func (gui *Gui) resetKeybindings() error { gui.g.DeleteAllKeybindings() - bindings := gui.GetCustomCommandKeybindings() - bindings, mouseBindings := gui.GetInitialKeybindings() // prepending because we want to give our custom keybindings precedence over default keybindings |