Skip to content

Commit bbd17ab

Browse files
committed
Add ContextMgr.NextInStack and use it to access side panel of focused main view
This way we don't have to abuse the parent context mechanism, which isn't meant for this purpose.
1 parent 12ed504 commit bbd17ab

File tree

7 files changed

+29
-11
lines changed

7 files changed

+29
-11
lines changed

pkg/gui/context.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,3 +357,19 @@ func (self *ContextMgr) CurrentPopup() []types.Context {
357357
return context.GetKind() == types.TEMPORARY_POPUP || context.GetKind() == types.PERSISTENT_POPUP
358358
})
359359
}
360+
361+
func (self *ContextMgr) NextInStack(c types.Context) types.Context {
362+
self.RLock()
363+
defer self.RUnlock()
364+
365+
for i := range self.ContextStack {
366+
if self.ContextStack[i].GetKey() == c.GetKey() {
367+
if i == 0 {
368+
return nil
369+
}
370+
return self.ContextStack[i-1]
371+
}
372+
}
373+
374+
panic("context not in stack")
375+
}

pkg/gui/controllers/context_lines_controller.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ func (self *ContextLinesController) currentSidePanel() types.Context {
131131
currentContext := self.c.Context().CurrentStatic()
132132
if currentContext.GetKey() == context.NORMAL_MAIN_CONTEXT_KEY ||
133133
currentContext.GetKey() == context.NORMAL_SECONDARY_CONTEXT_KEY {
134-
return currentContext.GetParentContext()
134+
if sidePanelContext := self.c.Context().NextInStack(currentContext); sidePanelContext != nil {
135+
return sidePanelContext
136+
}
135137
}
136138

137139
return currentContext

pkg/gui/controllers/main_view_controller.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ func (self *MainViewController) Context() types.Context {
7676

7777
func (self *MainViewController) togglePanel() error {
7878
if self.otherContext.GetView().Visible {
79-
self.otherContext.SetParentContext(self.context.GetParentContext())
8079
self.c.Context().Push(self.otherContext, types.OnFocusOpts{})
8180
}
8281

@@ -89,15 +88,14 @@ func (self *MainViewController) escape() error {
8988
}
9089

9190
func (self *MainViewController) onClickInAlreadyFocusedView(opts gocui.ViewMouseBindingOpts) error {
92-
parentCtx := self.context.GetParentContext()
93-
if parentCtx.GetOnClickFocusedMainView() != nil {
94-
return parentCtx.GetOnClickFocusedMainView()(self.context.GetViewName(), opts.Y)
91+
sidePanelContext := self.c.Context().NextInStack(self.context)
92+
if sidePanelContext != nil && sidePanelContext.GetOnClickFocusedMainView() != nil {
93+
return sidePanelContext.GetOnClickFocusedMainView()(self.context.GetViewName(), opts.Y)
9594
}
9695
return nil
9796
}
9897

9998
func (self *MainViewController) onClickInOtherViewOfMainViewPair(opts gocui.ViewMouseBindingOpts) error {
100-
self.context.SetParentContext(self.otherContext.GetParentContext())
10199
self.c.Context().Push(self.context, types.OnFocusOpts{
102100
ClickedWindowName: self.context.GetWindowName(),
103101
ClickedViewLineIdx: opts.Y,

pkg/gui/controllers/rename_similarity_threshold_controller.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ func (self *RenameSimilarityThresholdController) currentSidePanel() types.Contex
106106
currentContext := self.c.Context().CurrentStatic()
107107
if currentContext.GetKey() == context.NORMAL_MAIN_CONTEXT_KEY ||
108108
currentContext.GetKey() == context.NORMAL_SECONDARY_CONTEXT_KEY {
109-
return currentContext.GetParentContext()
109+
if sidePanelContext := self.c.Context().NextInStack(currentContext); sidePanelContext != nil {
110+
return sidePanelContext
111+
}
110112
}
111113

112114
return currentContext

pkg/gui/controllers/switch_to_focused_main_view_controller.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ func (self *SwitchToFocusedMainViewController) handleFocusMainView() error {
7272
}
7373

7474
func (self *SwitchToFocusedMainViewController) focusMainView(mainViewContext types.Context) error {
75-
mainViewContext.SetParentContext(self.context)
7675
if context, ok := mainViewContext.(types.ISearchableContext); ok {
7776
context.ClearSearchString()
7877
}

pkg/gui/types/context.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ type IContextMgr interface {
300300
CurrentStatic() Context
301301
CurrentSide() Context
302302
CurrentPopup() []Context
303+
NextInStack(context Context) Context
303304
IsCurrent(c Context) bool
304305
IsCurrentOrParent(c Context) bool
305306
ForEach(func(Context))

pkg/gui/view_helpers.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ func (gui *Gui) postRefreshUpdate(c types.Context) {
152152
// just don't rerender the view while searching, on the assumption that users will probably
153153
// either search or change their data, but not both at the same time.
154154
if !currentCtx.GetView().IsSearching() {
155-
parentCtx := currentCtx.GetParentContext()
156-
if parentCtx.GetKey() == c.GetKey() {
157-
parentCtx.HandleRenderToMain()
155+
sidePanelContext := gui.State.ContextMgr.NextInStack(currentCtx)
156+
if sidePanelContext != nil && sidePanelContext.GetKey() == c.GetKey() {
157+
sidePanelContext.HandleRenderToMain()
158158
}
159159
}
160160
}

0 commit comments

Comments
 (0)