mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-29 23:17:32 +02:00
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.
This commit is contained in:
parent
12ed50464b
commit
bbd17abc43
@ -357,3 +357,19 @@ func (self *ContextMgr) CurrentPopup() []types.Context {
|
|||||||
return context.GetKind() == types.TEMPORARY_POPUP || context.GetKind() == types.PERSISTENT_POPUP
|
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")
|
||||||
|
}
|
||||||
|
@ -131,7 +131,9 @@ func (self *ContextLinesController) currentSidePanel() types.Context {
|
|||||||
currentContext := self.c.Context().CurrentStatic()
|
currentContext := self.c.Context().CurrentStatic()
|
||||||
if currentContext.GetKey() == context.NORMAL_MAIN_CONTEXT_KEY ||
|
if currentContext.GetKey() == context.NORMAL_MAIN_CONTEXT_KEY ||
|
||||||
currentContext.GetKey() == context.NORMAL_SECONDARY_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
|
return currentContext
|
||||||
|
@ -76,7 +76,6 @@ func (self *MainViewController) Context() types.Context {
|
|||||||
|
|
||||||
func (self *MainViewController) togglePanel() error {
|
func (self *MainViewController) togglePanel() error {
|
||||||
if self.otherContext.GetView().Visible {
|
if self.otherContext.GetView().Visible {
|
||||||
self.otherContext.SetParentContext(self.context.GetParentContext())
|
|
||||||
self.c.Context().Push(self.otherContext, types.OnFocusOpts{})
|
self.c.Context().Push(self.otherContext, types.OnFocusOpts{})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,15 +88,14 @@ func (self *MainViewController) escape() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *MainViewController) onClickInAlreadyFocusedView(opts gocui.ViewMouseBindingOpts) error {
|
func (self *MainViewController) onClickInAlreadyFocusedView(opts gocui.ViewMouseBindingOpts) error {
|
||||||
parentCtx := self.context.GetParentContext()
|
sidePanelContext := self.c.Context().NextInStack(self.context)
|
||||||
if parentCtx.GetOnClickFocusedMainView() != nil {
|
if sidePanelContext != nil && sidePanelContext.GetOnClickFocusedMainView() != nil {
|
||||||
return parentCtx.GetOnClickFocusedMainView()(self.context.GetViewName(), opts.Y)
|
return sidePanelContext.GetOnClickFocusedMainView()(self.context.GetViewName(), opts.Y)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *MainViewController) onClickInOtherViewOfMainViewPair(opts gocui.ViewMouseBindingOpts) error {
|
func (self *MainViewController) onClickInOtherViewOfMainViewPair(opts gocui.ViewMouseBindingOpts) error {
|
||||||
self.context.SetParentContext(self.otherContext.GetParentContext())
|
|
||||||
self.c.Context().Push(self.context, types.OnFocusOpts{
|
self.c.Context().Push(self.context, types.OnFocusOpts{
|
||||||
ClickedWindowName: self.context.GetWindowName(),
|
ClickedWindowName: self.context.GetWindowName(),
|
||||||
ClickedViewLineIdx: opts.Y,
|
ClickedViewLineIdx: opts.Y,
|
||||||
|
@ -106,7 +106,9 @@ func (self *RenameSimilarityThresholdController) currentSidePanel() types.Contex
|
|||||||
currentContext := self.c.Context().CurrentStatic()
|
currentContext := self.c.Context().CurrentStatic()
|
||||||
if currentContext.GetKey() == context.NORMAL_MAIN_CONTEXT_KEY ||
|
if currentContext.GetKey() == context.NORMAL_MAIN_CONTEXT_KEY ||
|
||||||
currentContext.GetKey() == context.NORMAL_SECONDARY_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
|
return currentContext
|
||||||
|
@ -72,7 +72,6 @@ func (self *SwitchToFocusedMainViewController) handleFocusMainView() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *SwitchToFocusedMainViewController) focusMainView(mainViewContext types.Context) error {
|
func (self *SwitchToFocusedMainViewController) focusMainView(mainViewContext types.Context) error {
|
||||||
mainViewContext.SetParentContext(self.context)
|
|
||||||
if context, ok := mainViewContext.(types.ISearchableContext); ok {
|
if context, ok := mainViewContext.(types.ISearchableContext); ok {
|
||||||
context.ClearSearchString()
|
context.ClearSearchString()
|
||||||
}
|
}
|
||||||
|
@ -300,6 +300,7 @@ type IContextMgr interface {
|
|||||||
CurrentStatic() Context
|
CurrentStatic() Context
|
||||||
CurrentSide() Context
|
CurrentSide() Context
|
||||||
CurrentPopup() []Context
|
CurrentPopup() []Context
|
||||||
|
NextInStack(context Context) Context
|
||||||
IsCurrent(c Context) bool
|
IsCurrent(c Context) bool
|
||||||
IsCurrentOrParent(c Context) bool
|
IsCurrentOrParent(c Context) bool
|
||||||
ForEach(func(Context))
|
ForEach(func(Context))
|
||||||
|
@ -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
|
// 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.
|
// either search or change their data, but not both at the same time.
|
||||||
if !currentCtx.GetView().IsSearching() {
|
if !currentCtx.GetView().IsSearching() {
|
||||||
parentCtx := currentCtx.GetParentContext()
|
sidePanelContext := gui.State.ContextMgr.NextInStack(currentCtx)
|
||||||
if parentCtx.GetKey() == c.GetKey() {
|
if sidePanelContext != nil && sidePanelContext.GetKey() == c.GetKey() {
|
||||||
parentCtx.HandleRenderToMain()
|
sidePanelContext.HandleRenderToMain()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user