summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-04-15 14:51:11 +1000
committerJesse Duffield <jessedduffield@gmail.com>2023-04-30 13:19:53 +1000
commita5c72d056ddbd639db3597ffb19a60e0cbae1826 (patch)
tree48cc98f6ec47aa63597cf2c62995e4b7bb34bf36
parent8a86de85c86236dc0bf72e7005d25b4772237a1f (diff)
ensure initial context is set when entering submodule
-rw-r--r--pkg/gui/context.go3
-rw-r--r--pkg/gui/controllers.go2
-rw-r--r--pkg/gui/gui.go21
-rw-r--r--pkg/gui/keybindings.go4
4 files changed, 15 insertions, 15 deletions
diff --git a/pkg/gui/context.go b/pkg/gui/context.go
index 4c403973f..28dc5e2b2 100644
--- a/pkg/gui/context.go
+++ b/pkg/gui/context.go
@@ -23,12 +23,11 @@ type ContextMgr struct {
}
func NewContextMgr(
- initialContext types.Context,
gui *Gui,
allContexts *context.ContextTree,
) *ContextMgr {
return &ContextMgr{
- ContextStack: []types.Context{initialContext},
+ ContextStack: []types.Context{},
RWMutex: sync.RWMutex{},
gui: gui,
allContexts: allContexts,
diff --git a/pkg/gui/controllers.go b/pkg/gui/controllers.go
index 88b9dee2e..344de939e 100644
--- a/pkg/gui/controllers.go
+++ b/pkg/gui/controllers.go
@@ -16,7 +16,7 @@ func (gui *Gui) Helpers() *helpers.Helpers {
return gui.helpers
}
-func (gui *Gui) resetControllers() {
+func (gui *Gui) resetHelpersAndControllers() {
helperCommon := gui.c
refsHelper := helpers.NewRefsHelper(helperCommon)
diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go
index d46d21a3e..49dbd556c 100644
--- a/pkg/gui/gui.go
+++ b/pkg/gui/gui.go
@@ -291,14 +291,18 @@ func (gui *Gui) onNewRepo(startArgs appTypes.StartArgs, reuseState bool) error {
return err
}
- gui.resetState(startArgs, reuseState)
+ contextToPush := gui.resetState(startArgs, reuseState)
- gui.resetControllers()
+ gui.resetHelpersAndControllers()
if err := gui.resetKeybindings(); err != nil {
return err
}
+ if err := gui.c.PushContext(contextToPush); err != nil {
+ return err
+ }
+
return nil
}
@@ -311,7 +315,7 @@ func (gui *Gui) onNewRepo(startArgs appTypes.StartArgs, reuseState bool) error {
// it gets a bit confusing to land back in the status panel when visiting a repo
// you've already switched from. There's no doubt some easy way to make the UX
// optimal for all cases but I'm too lazy to think about what that is right now
-func (gui *Gui) resetState(startArgs appTypes.StartArgs, reuseState bool) {
+func (gui *Gui) resetState(startArgs appTypes.StartArgs, reuseState bool) types.Context {
currentDir, err := os.Getwd()
if reuseState {
@@ -326,7 +330,7 @@ func (gui *Gui) resetState(startArgs appTypes.StartArgs, reuseState bool) {
gui.State.CurrentPopupOpts = nil
gui.Mutexes.PopupMutex.Unlock()
- return
+ return gui.c.CurrentContext()
}
} else {
gui.c.Log.Error(err)
@@ -335,7 +339,6 @@ func (gui *Gui) resetState(startArgs appTypes.StartArgs, reuseState bool) {
contextTree := gui.contextTree()
- initialContext := initialContext(contextTree, startArgs)
initialScreenMode := initialScreenMode(startArgs, gui.Config)
gui.State = &GuiRepoState{
@@ -356,16 +359,14 @@ func (gui *Gui) resetState(startArgs appTypes.StartArgs, reuseState bool) {
},
ScreenMode: initialScreenMode,
// TODO: only use contexts from context manager
- ContextMgr: NewContextMgr(initialContext, gui, contextTree),
+ ContextMgr: NewContextMgr(gui, contextTree),
Contexts: contextTree,
WindowViewNameMap: initialWindowViewNameMap(contextTree),
}
- if err := gui.c.PushContext(initialContext); err != nil {
- gui.c.Log.Error(err)
- }
-
gui.RepoStateMap[Repo(currentDir)] = gui.State
+
+ return initialContext(contextTree, startArgs)
}
func initialWindowViewNameMap(contextTree *context.ContextTree) *utils.ThreadSafeMap[string, string] {
diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go
index 6095e6431..c4715de52 100644
--- a/pkg/gui/keybindings.go
+++ b/pkg/gui/keybindings.go
@@ -52,8 +52,8 @@ func (self *Gui) GetCheatsheetKeybindings() []*types.Binding {
self.helpers = helpers.NewStubHelpers()
self.State = &GuiRepoState{}
self.State.Contexts = self.contextTree()
- self.State.ContextMgr = NewContextMgr(nil, self, self.State.Contexts)
- self.resetControllers()
+ self.State.ContextMgr = NewContextMgr(self, self.State.Contexts)
+ self.resetHelpersAndControllers()
bindings, _ := self.GetInitialKeybindings()
return bindings
}