diff --git a/pkg/gui/context.go b/pkg/gui/context.go index ca5727d38..45b2bdf34 100644 --- a/pkg/gui/context.go +++ b/pkg/gui/context.go @@ -357,3 +357,19 @@ func (self *ContextMgr) CurrentPopup() []types.Context { return context.GetKind() == types.TEMPORARY_POPUP || context.GetKind() == types.PERSISTENT_POPUP }) } + +func (self *ContextMgr) NextInStack(c types.Context) types.Context { + self.RLock() + defer self.RUnlock() + + for i := range self.ContextStack { + if self.ContextStack[i].GetKey() == c.GetKey() { + if i == 0 { + return nil + } + return self.ContextStack[i-1] + } + } + + panic("context not in stack") +} diff --git a/pkg/gui/controllers/context_lines_controller.go b/pkg/gui/controllers/context_lines_controller.go index 8e35d5103..aec202aeb 100644 --- a/pkg/gui/controllers/context_lines_controller.go +++ b/pkg/gui/controllers/context_lines_controller.go @@ -131,7 +131,9 @@ func (self *ContextLinesController) currentSidePanel() types.Context { currentContext := self.c.Context().CurrentStatic() if currentContext.GetKey() == context.NORMAL_MAIN_CONTEXT_KEY || currentContext.GetKey() == context.NORMAL_SECONDARY_CONTEXT_KEY { - return currentContext.GetParentContext() + if sidePanelContext := self.c.Context().NextInStack(currentContext); sidePanelContext != nil { + return sidePanelContext + } } return currentContext diff --git a/pkg/gui/controllers/main_view_controller.go b/pkg/gui/controllers/main_view_controller.go index e6b209286..5dfdb3233 100644 --- a/pkg/gui/controllers/main_view_controller.go +++ b/pkg/gui/controllers/main_view_controller.go @@ -56,21 +56,16 @@ func (self *MainViewController) GetKeybindings(opts types.KeybindingsOpts) []*ty func (self *MainViewController) GetMouseKeybindings(opts types.KeybindingsOpts) []*gocui.ViewMouseBinding { return []*gocui.ViewMouseBinding{ { - ViewName: self.context.GetViewName(), - Key: gocui.MouseLeft, - Handler: func(opts gocui.ViewMouseBindingOpts) error { - if self.isFocused() { - return self.onClick(opts) - } - - self.context.SetParentContext(self.otherContext.GetParentContext()) - self.c.Context().Push(self.context, types.OnFocusOpts{ - ClickedWindowName: self.context.GetWindowName(), - ClickedViewLineIdx: opts.Y, - }) - - return nil - }, + ViewName: self.context.GetViewName(), + Key: gocui.MouseLeft, + Handler: self.onClickInAlreadyFocusedView, + FocusedView: self.context.GetViewName(), + }, + { + ViewName: self.context.GetViewName(), + Key: gocui.MouseLeft, + Handler: self.onClickInOtherViewOfMainViewPair, + FocusedView: self.otherContext.GetViewName(), }, } } @@ -81,7 +76,6 @@ func (self *MainViewController) Context() types.Context { func (self *MainViewController) togglePanel() error { if self.otherContext.GetView().Visible { - self.otherContext.SetParentContext(self.context.GetParentContext()) self.c.Context().Push(self.otherContext, types.OnFocusOpts{}) } @@ -93,14 +87,23 @@ func (self *MainViewController) escape() error { return nil } -func (self *MainViewController) onClick(opts gocui.ViewMouseBindingOpts) error { - parentCtx := self.context.GetParentContext() - if parentCtx.GetOnClickFocusedMainView() != nil { - return parentCtx.GetOnClickFocusedMainView()(self.context.GetViewName(), opts.Y) +func (self *MainViewController) onClickInAlreadyFocusedView(opts gocui.ViewMouseBindingOpts) error { + sidePanelContext := self.c.Context().NextInStack(self.context) + if sidePanelContext != nil && sidePanelContext.GetOnClickFocusedMainView() != nil { + return sidePanelContext.GetOnClickFocusedMainView()(self.context.GetViewName(), opts.Y) } return nil } +func (self *MainViewController) onClickInOtherViewOfMainViewPair(opts gocui.ViewMouseBindingOpts) error { + self.c.Context().Push(self.context, types.OnFocusOpts{ + ClickedWindowName: self.context.GetWindowName(), + ClickedViewLineIdx: opts.Y, + }) + + return nil +} + func (self *MainViewController) openSearch() error { if manager := self.c.GetViewBufferManagerForView(self.context.GetView()); manager != nil { manager.ReadToEnd(func() { @@ -112,7 +115,3 @@ func (self *MainViewController) openSearch() error { return nil } - -func (self *MainViewController) isFocused() bool { - return self.c.Context().Current().GetKey() == self.context.GetKey() -} diff --git a/pkg/gui/controllers/rename_similarity_threshold_controller.go b/pkg/gui/controllers/rename_similarity_threshold_controller.go index 88c611723..790c005a9 100644 --- a/pkg/gui/controllers/rename_similarity_threshold_controller.go +++ b/pkg/gui/controllers/rename_similarity_threshold_controller.go @@ -106,7 +106,9 @@ func (self *RenameSimilarityThresholdController) currentSidePanel() types.Contex currentContext := self.c.Context().CurrentStatic() if currentContext.GetKey() == context.NORMAL_MAIN_CONTEXT_KEY || currentContext.GetKey() == context.NORMAL_SECONDARY_CONTEXT_KEY { - return currentContext.GetParentContext() + if sidePanelContext := self.c.Context().NextInStack(currentContext); sidePanelContext != nil { + return sidePanelContext + } } return currentContext diff --git a/pkg/gui/controllers/switch_to_focused_main_view_controller.go b/pkg/gui/controllers/switch_to_focused_main_view_controller.go index cb03f5e15..1973e3d63 100644 --- a/pkg/gui/controllers/switch_to_focused_main_view_controller.go +++ b/pkg/gui/controllers/switch_to_focused_main_view_controller.go @@ -60,20 +60,18 @@ func (self *SwitchToFocusedMainViewController) Context() types.Context { } func (self *SwitchToFocusedMainViewController) onClickMain(opts gocui.ViewMouseBindingOpts) error { - return self.focusMainView("main") + return self.focusMainView(self.c.Contexts().Normal) } func (self *SwitchToFocusedMainViewController) onClickSecondary(opts gocui.ViewMouseBindingOpts) error { - return self.focusMainView("secondary") + return self.focusMainView(self.c.Contexts().NormalSecondary) } func (self *SwitchToFocusedMainViewController) handleFocusMainView() error { - return self.focusMainView("main") + return self.focusMainView(self.c.Contexts().Normal) } -func (self *SwitchToFocusedMainViewController) focusMainView(mainViewName string) error { - mainViewContext := self.c.Helpers().Window.GetContextForWindow(mainViewName) - mainViewContext.SetParentContext(self.context) +func (self *SwitchToFocusedMainViewController) focusMainView(mainViewContext types.Context) error { if context, ok := mainViewContext.(types.ISearchableContext); ok { context.ClearSearchString() } diff --git a/pkg/gui/types/context.go b/pkg/gui/types/context.go index b75d97fb6..1c9759486 100644 --- a/pkg/gui/types/context.go +++ b/pkg/gui/types/context.go @@ -300,6 +300,7 @@ type IContextMgr interface { CurrentStatic() Context CurrentSide() Context CurrentPopup() []Context + NextInStack(context Context) Context IsCurrent(c Context) bool IsCurrentOrParent(c Context) bool ForEach(func(Context)) diff --git a/pkg/gui/view_helpers.go b/pkg/gui/view_helpers.go index 383550d91..081b2a426 100644 --- a/pkg/gui/view_helpers.go +++ b/pkg/gui/view_helpers.go @@ -152,9 +152,9 @@ func (gui *Gui) postRefreshUpdate(c types.Context) { // just don't rerender the view while searching, on the assumption that users will probably // either search or change their data, but not both at the same time. if !currentCtx.GetView().IsSearching() { - parentCtx := currentCtx.GetParentContext() - if parentCtx.GetKey() == c.GetKey() { - parentCtx.HandleRenderToMain() + sidePanelContext := gui.State.ContextMgr.NextInStack(currentCtx) + if sidePanelContext != nil && sidePanelContext.GetKey() == c.GetKey() { + sidePanelContext.HandleRenderToMain() } } }