diff --git a/pkg/gui/context.go b/pkg/gui/context.go index c63defba4..d78388bf0 100644 --- a/pkg/gui/context.go +++ b/pkg/gui/context.go @@ -11,7 +11,6 @@ import ( "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/gui/context" "github.com/jesseduffield/lazygit/pkg/gui/types" - "github.com/samber/lo" ) func (gui *Gui) popupViewNames() []string { @@ -135,10 +134,6 @@ func (gui *Gui) returnFromContext() error { } func (gui *Gui) deactivateContext(c types.Context) error { - if c.IsTransient() { - gui.resetWindowContext(c) - } - view, _ := gui.g.View(c.GetViewName()) if view != nil && view.IsSearching() { @@ -150,8 +145,7 @@ func (gui *Gui) deactivateContext(c types.Context) error { // if we are the kind of context that is sent to back upon deactivation, we should do that if view != nil && (c.GetKind() == types.TEMPORARY_POPUP || - c.GetKind() == types.PERSISTENT_POPUP || - c.IsTransient()) { + c.GetKind() == types.PERSISTENT_POPUP) { view.Visible = false } @@ -391,16 +385,6 @@ func (gui *Gui) onViewFocusLost(oldView *gocui.View, newView *gocui.View) error _ = oldView.SetOriginX(0) - if !lo.Contains([]*gocui.View{gui.Views.Main, gui.Views.Secondary, gui.Views.Search}, newView) { - for _, context := range gui.TransientContexts() { - if oldView.Name() == context.GetViewName() { - if err := gui.deactivateContext(context); err != nil { - return err - } - } - } - } - return nil } @@ -475,7 +459,8 @@ func (gui *Gui) getSideContextSelectedItemId() string { } func (gui *Gui) isContextVisible(c types.Context) bool { - return gui.State.WindowViewNameMap[c.GetWindowName()] == c.GetViewName() && gui.State.ViewContextMap.Get(c.GetViewName()).GetKey() == c.GetKey() + return gui.State.WindowViewNameMap[c.GetWindowName()] == c.GetViewName() && + gui.State.ViewContextMap.Get(c.GetViewName()).GetKey() == c.GetKey() } // currently unused diff --git a/pkg/gui/types/context.go b/pkg/gui/types/context.go index bf4051538..1f7d753e7 100644 --- a/pkg/gui/types/context.go +++ b/pkg/gui/types/context.go @@ -33,8 +33,10 @@ type IBaseContext interface { SetWindowName(string) GetKey() ContextKey IsFocusable() bool - // if a context is transient, then when it loses focus, its corresponding view - // returns control of the window to the default view for that window + // if a context is transient, then it only appears via some keybinding on another + // context. Until we add support for having multiple of the same context, no two + // of the same transient context can appear at once meaning one might be 'stolen' + // from another window. IsTransient() bool // returns the desired title for the view upon activation. If there is no desired title (returns empty string), then diff --git a/pkg/gui/window.go b/pkg/gui/window.go index 88d93d5ae..d347081ab 100644 --- a/pkg/gui/window.go +++ b/pkg/gui/window.go @@ -25,6 +25,10 @@ func (gui *Gui) setWindowContext(c types.Context) { gui.State.WindowViewNameMap = map[string]string{} } + if c.IsTransient() { + gui.resetWindowContext(c) + } + gui.State.WindowViewNameMap[c.GetWindowName()] = c.GetViewName() } @@ -32,10 +36,12 @@ func (gui *Gui) currentWindow() string { return gui.currentContext().GetWindowName() } +// assumes the context's windowName has been set to the new window if necessary func (gui *Gui) resetWindowContext(c types.Context) { - // we assume here that the window contains as its default view a view with the same name as the window - windowName := c.GetWindowName() - if gui.State.WindowViewNameMap[windowName] == c.GetViewName() { - gui.State.WindowViewNameMap[windowName] = windowName + for windowName, viewName := range gui.State.WindowViewNameMap { + if viewName == c.GetViewName() && windowName != c.GetWindowName() { + // we assume here that the window contains as its default view a view with the same name as the window + gui.State.WindowViewNameMap[windowName] = windowName + } } }