From 652c97d2396c53d24fbb4a461573fa2ab381eab6 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sat, 25 Sep 2021 13:21:28 +1000 Subject: [PATCH] honour options menu press --- pkg/gui/context.go | 48 +++++++++++++++++++++++-------------------- pkg/gui/menu_panel.go | 2 +- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/pkg/gui/context.go b/pkg/gui/context.go index af5fdc71b..a74b12749 100644 --- a/pkg/gui/context.go +++ b/pkg/gui/context.go @@ -128,33 +128,37 @@ func (gui *Gui) pushContextWithView(viewName string) error { func (gui *Gui) returnFromContext() error { gui.g.Update(func(*gocui.Gui) error { - gui.State.ContextManager.Lock() - - if len(gui.State.ContextManager.ContextStack) == 1 { - // cannot escape from bottommost context - gui.State.ContextManager.Unlock() - return nil - } - - n := len(gui.State.ContextManager.ContextStack) - 1 - - currentContext := gui.State.ContextManager.ContextStack[n] - newContext := gui.State.ContextManager.ContextStack[n-1] - - gui.State.ContextManager.ContextStack = gui.State.ContextManager.ContextStack[:n] - - gui.State.ContextManager.Unlock() - - if err := gui.deactivateContext(currentContext); err != nil { - return err - } - - return gui.activateContext(newContext) + return gui.returnFromContextSync() }) return nil } +func (gui *Gui) returnFromContextSync() error { + gui.State.ContextManager.Lock() + + if len(gui.State.ContextManager.ContextStack) == 1 { + // cannot escape from bottommost context + gui.State.ContextManager.Unlock() + return nil + } + + n := len(gui.State.ContextManager.ContextStack) - 1 + + currentContext := gui.State.ContextManager.ContextStack[n] + newContext := gui.State.ContextManager.ContextStack[n-1] + + gui.State.ContextManager.ContextStack = gui.State.ContextManager.ContextStack[:n] + + gui.State.ContextManager.Unlock() + + if err := gui.deactivateContext(currentContext); err != nil { + return err + } + + return gui.activateContext(newContext) +} + func (gui *Gui) deactivateContext(c Context) error { view, _ := gui.g.View(c.GetViewName()) diff --git a/pkg/gui/menu_panel.go b/pkg/gui/menu_panel.go index fcb1f7a7b..af56e29b9 100644 --- a/pkg/gui/menu_panel.go +++ b/pkg/gui/menu_panel.go @@ -43,7 +43,7 @@ func (gui *Gui) getMenuOptions() map[string]string { } func (gui *Gui) handleMenuClose() error { - return gui.returnFromContext() + return gui.returnFromContextSync() } type createMenuOptions struct {