diff --git a/pkg/gui/context.go b/pkg/gui/context.go index f20e3ff33..7b5ac5cdc 100644 --- a/pkg/gui/context.go +++ b/pkg/gui/context.go @@ -464,14 +464,19 @@ func (gui *Gui) returnFromContext() error { } func (gui *Gui) deactivateContext(c Context) error { - // if we are the kind of context that is sent to back upon deactivation, we should do that - if c.GetKind() == TEMPORARY_POPUP || c.GetKind() == PERSISTENT_POPUP || c.GetKey() == COMMIT_FILES_CONTEXT_KEY { - view, err := gui.g.View(c.GetViewName()) - if err == nil { - view.Visible = false + view, _ := gui.g.View(c.GetViewName()) + + if view != nil && view.IsSearching() { + if err := gui.onSearchEscape(); err != nil { + return err } } + // if we are the kind of context that is sent to back upon deactivation, we should do that + if view != nil && c.GetKind() == TEMPORARY_POPUP || c.GetKind() == PERSISTENT_POPUP || c.GetKey() == COMMIT_FILES_CONTEXT_KEY { + view.Visible = false + } + if err := c.HandleFocusLost(); err != nil { return err } @@ -674,12 +679,6 @@ func (gui *Gui) onViewFocusLost(oldView *gocui.View, newView *gocui.View) error return nil } - if oldView.IsSearching() && newView != gui.Views.Search { - if err := gui.onSearchEscape(); err != nil { - return err - } - } - if oldView == gui.Views.CommitFiles && newView != gui.Views.Main && newView != gui.Views.Secondary && newView != gui.Views.Search { gui.resetWindowForView(gui.Views.CommitFiles) if err := gui.deactivateContext(gui.State.Contexts.CommitFiles); err != nil {