From 524bf83a4a681408c3fb57818f6968cab632e0ae Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Mon, 13 Jun 2022 11:01:26 +1000 Subject: refactor to only have one context per view --- pkg/gui/gui_common.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'pkg/gui/gui_common.go') diff --git a/pkg/gui/gui_common.go b/pkg/gui/gui_common.go index 89abe92ba..587a7fb86 100644 --- a/pkg/gui/gui_common.go +++ b/pkg/gui/gui_common.go @@ -1,6 +1,8 @@ package gui import ( + "errors" + "github.com/jesseduffield/lazygit/pkg/commands/oscommands" "github.com/jesseduffield/lazygit/pkg/config" "github.com/jesseduffield/lazygit/pkg/gui/types" @@ -39,7 +41,17 @@ func (self *guiCommon) RunSubprocess(cmdObj oscommands.ICmdObj) (bool, error) { } func (self *guiCommon) PushContext(context types.Context, opts ...types.OnFocusOpts) error { - return self.gui.pushContext(context, opts...) + singleOpts := types.OnFocusOpts{} + if len(opts) > 0 { + // using triple dot but you should only ever pass one of these opt structs + if len(opts) > 1 { + return errors.New("cannot pass multiple opts to pushContext") + } + + singleOpts = opts[0] + } + + return self.gui.pushContext(context, singleOpts) } func (self *guiCommon) PopContext() error { @@ -50,6 +62,14 @@ func (self *guiCommon) CurrentContext() types.Context { return self.gui.currentContext() } +func (self *guiCommon) CurrentStaticContext() types.Context { + return self.gui.currentStaticContext() +} + +func (self *guiCommon) IsCurrentContext(c types.Context) bool { + return self.CurrentContext().GetKey() == c.GetKey() +} + func (self *guiCommon) GetAppState() *config.AppState { return self.gui.Config.GetAppState() } -- cgit v1.2.3